Encapsula)on, cont d. Polymorphism, Inheritance part 1. COMP 401, Spring 2015 Lecture 7 1/29/2015
|
|
- Allison Wiggins
- 6 years ago
- Views:
Transcription
1 Encapsula)on, cont d. Polymorphism, Inheritance part 1 COMP 401, Spring 2015 Lecture 7 1/29/2015
2 Encapsula)on In Prac)ce Part 2: Separate Exposed Behavior Define an interface for all exposed behavior In Java, an interface is like a contract. Indicates that a certain set of public methods are available. One or more classes can indicate that they implement the interface. Name of interface can be used as a type name Just like class names are used as type names. Value of an interface type variable can be set to any object that is an instance of a class that implements the interface. Mark constructors as public
3 Interfaces in Java Like classes, should go in their own.java file Should have same name as file Only one public interface per file. Body of interface is a just list of method signatures. Implemen)ng classes MUST declare these methods as public Form: public interface InterfaceName {! type method1(parameters);! type method2(parameters);! // etc! }! Classes specify which interfaces they implement with implements modifier as in: public class ClassName implements InterfaceA, InferfaceB {!
4 Interface Naming Conven)ons Interface name must be different from class names that implement the interface. Conven)on A Start all interface names with I for interface. For example: ITriangle, IPoint Class names can be anything that is not in this form. Conven)on B Use generic abstrac)on name for interface. Make class names descrip)ve of implementa)on If no natural way to do this, simply append Impl to generic abstrac)on name to differen)ate. Personally, I generally go with conven)on B.
5 lec6. v6 Separates Point into an interface and an implemen)ng class. No)ce that distanceto() and equals() are part of behavior I want the abstrac)on to expose. Must be marked public No)ce that main method uses variables with type Point (the interface name), but that the actual object is created as an instance of a specific class that implements the interface Point. No)ce that Triangle only interacts with the methods specified in the Point interface.
6 Advantage of Encapsula)on Can provide different implementa)ons of the same behavior lec6.v7 Create a new implementa)on of Point based on polar coordinates.
7 Exposed vs Internal Behavior Exposed behavior should be reflected in the interface(s) that a class implements Recall that any method declared in an interface must be defined by an implemen)ng class as a public method. Internal behavior should be hidden Use private modifier on these methods to ensure that access only occurs within the class
8 lec6.v8 Con)nued applica)on of encapsula)on principle to Triangle by defining Triangle as an interface rewri)ng what used to be the class Triangle as the class PointTriangle that implements the interface hiding internal behaviors as private methods
9 Summing Up A Java file defines one public class or public interface. To support encapsula)on: External behavior of an abstrac)on defined as an interface. JavaBeans geders and seders for direct or derived proper)es. Other methods that are part of the abstrac)on. A class provides the implementa)on of one or more interfaces. All fields within a class are marked as private. Public constructor Methods that implement any interface(s) must be public. Internal methods marked as private.
10 Do you always need an interface? Best prac)ce is to separate an abstrac)on into an interface and a class that implements it. Allows you to have mul)ple classes that implement the interface in different ways. For simple classes where you know there will only be one implementa)on, you can get away without defining the interface separately. Should s)ll: mark fields as private, constructor as public, make a dis)nc)on between public methods for external behavior and private methods for internal behavior
11 Polymorphism Poly = many, morph = forms General principle of providing access to an abstrac)on or method in many forms Idea is that different forms fit different contexts Goal of the underlying func)onality is the same. In OO programming, principle is evident in a number of different places. Constructor overloading Method overloading
12 Constructors What happens when you don t define a constructor. Default constructor with no arguments. lec7.ex1 Creates new object with all fields set to default value Numeric fields set to 0 Boolean fields set to false String, Array, and any other sort of reference value field set to null.
13 An aside on puing more than one class in a file. A Java file can only have one public class. A class marked public can be imported into other code. Must match file name One or more non- public classes in a Java file can also be defined Only available to code in the same package. Does not have to match file name Oken used to define classes that are related to the public class in that file.
14 Constructor Overloading Can define mul)ple versions of the constructor. Dis)nguished from each other by type and number of parameters Must be some difference otherwise the compiler won t be able to tell them apart. When you use the constructor, the right one will be chosen based on the parameters provided. Note that once you define at least one constructor, the implicit, default no- argument constructor is not automa)cally available. lec7.ex2
15 Constructor Chaining Common padern is to chain one constructor off of another. To do this, the first line of code in the constructor must be the this keyword used as if a func)on with parameters. The matching constructor is called first and allowed to execute. Then any subsequent code is executed. Can chain mul)ple constructors one on to another lec7.ex3
16 Method Overloading Regular methods can also be overloaded Same method name defined more than once. Return type may or may not be the same. But usually is. Method type must be the same. Instance method or sta)c class method Same access modifier Parameter list must somehow be different Again, this is how the compiler knows which one is meant. Either different in number or type (or both) One version can call another No restric)ons on when No special syntax lec7.ex4, lec7.ex5
17 Why Overload? Provides access to constructor / method in a more context specific way. Limita)ons of overloading Does not handle the case when you have two different situa)ons that aren t dis)nguished by the number or type of parameters being passed.
18 Recap of Interfaces A contract for behavior. Defined by a set of method signatures. Acts as a data type. No implementa)on. Specific classes implement the interface
19 Song and Video as Media public interface Media { int getlengthinseconds(); double getlengthinminutes(); int getra)ng(); void setra)ng(int new_ra)ng); String getname(); } public class Song implements Media {... We expect Song and Video to have methods matching those specified in Media. public class Video implements Media {...
20 Is- A and cas)ng A class that implements an interface creates an is- a rela)onship between class data type and the interface data type. A implements B => A is a B Song is a Media Video is a Media Cas)ng allowed across an is- a rela)onship. Song s = new Song(); Media m; m = (Media) s; Video v = new Video(); Media m; m = (Media) v; Video v = new Video(); Song s; s = (Song) v; 20
21 Inheritance What is inheritance in real life? Characteris)cs / resources that you receive from your parents Get these automa)cally. Part of who you are. Similar idea in object- oriented programming. In Java, concept of inheritance applied to both interfaces and classes. Both signaled by the keyword extends Similar in concept, but details are dis)nctly different. Class inheritance more complex.
22 Extending Interfaces Adds methods to the contract. Original: parent interface, super interface New: subinterface, child interface, extended interface Created by using the extends keyword. public interface CompressedMedia extends Media { int getcompressedsize(); int getuncompressedsize(); Media uncompress(); }
23 Extension Creates Hierarchy Is- A rela)onship is transi)ve up the hierarchy. Methods for both must be provided. Media extends Compressed Media public class Song implements CompressedMedia {... Song s = new Song(); CompressedMedia cm = (CompressedMedia) s; Media m = (Media) s; OK because s is a Compressed Media OK because s is a Media by virtue of extension. Song s2 = (Song) m; Cas=ng from interface back to specific object type is allowed, but at run=me, if the object s type does not actually match, a run=me excep=on will be thrown.
24 Extension vs. Mul)ple Interfaces Interface extension appropriate when addi)onal methods make no sense without methods of the parent interface. Alterna)vely, can use mul)ple interfaces together as facets of an object.
25 Extension vs. Mul)ple Interfaces public interface Compressed { int getcompressedsize(); int getuncompressedsize(); Media uncompress(); } Instead of extending Media, Compressed is a separate interface and Song implements both. public class Song implements Compressed, Media {... public interface Media { int getlengthinseconds(); double getlengthinminutes(); int getra)ng(); void setra)ng(int new_ra)ng); String getname(); } Song s = new Song(); Media m = (Media) s; Song is a Media AND Song is a Compressed. Compressed c = (Compressed) s;
26 Subinterface Mul)ple Inheritance Mul)ple inheritance for interfaces is allowed. A subinterface can extend more than one exis)ng interface. In this case, just a union of all methods declared in all of the parent interfaces. lec7.ex6 Plus, of course, any addi)onal ones added by the subinterface.
27 Mo)va)ng Enumera)ons Oken need to model part of an object as one value from a set of finite choices Examples: Suite of a playing card Day of week Direc)ons of a compass One approach is to use named constants lec7.ex7 Drawbacks of this approach No type safety No value safety
28 Simple Java Enumera)ons General syntax: access_type enum EnumName {symbol, symbol,...};! Example: public enum Genre {POP, RAP, JAZZ, INDIE, CLASSICAL} Enumera)on name acts as the data type for the enumerated values. Enumerated values available as EnumName.symbol as in: Genre.POP Outside of the class Fully qualified name required as in: Song.Genre.POP Symbol names don t have to all caps, but that is tradi)onal lec7.ex8
29 Enumera)ons in Interfaces Enumera)ons can be defined within an interface. Useful when enumera)on is related to the interface as an abstrac)on and will be needed within any specific implementa)on.
30 Not so simple enumera)ons Java enumera)ons are actually much more powerful than this. Check out this tutorial for more: hdp://javarevisited.blogspot.com/2011/08/ enum- in- java- example- tutorial.html Also posted on course resources page in Piazza.
Polymorphism. COMP 401, Fall 2017 Lecture 08
Polymorphism COMP 401, Fall 2017 Lecture 08 Polymorphism Poly = many, morph = forms General principle of providing access to an abstraceon or method in many forms Idea is that different forms fit different
More informationSubclassing, con.nued Method overriding, virtual methods, abstract classes/methods. COMP 401, Spring 2015 Lecture 9 2/19/2015
Subclassing, con.nued Method overriding, virtual methods, abstract classes/methods COMP 401, Spring 2015 Lecture 9 2/19/2015 Subclassing So Far A subclass inherits implementa.on details from its superclass
More informationObjec,ves. Review: Object-Oriented Programming. Object-oriented programming in Java. What is OO programming? Benefits?
Objec,ves Object-oriented programming in Java Ø Encapsula,on Ø Access modifiers Ø Using others classes Ø Defining own classes Sept 16, 2016 Sprenkle - CSCI209 1 Review: Object-Oriented Programming What
More informationWhy OO programming? want but aren t. Ø What are its components?
9/21/15 Objec,ves Assign 1 Discussion Object- oriented programming in Java Java Conven,ons: Ø Constructors Ø Default constructors Ø Sta,c methods, variables Ø Inherited methods Ø Class names: begin with
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 20 Feb 29, 2012 Transi@on to Java II DON T PANIC Smoothing the transi@on Eclipse set- up instruc@ons in lab today/tomorrow First Java homework assignment
More informationGarbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; }
Objec,ves Inheritance Ø Overriding methods Garbage collec,on Parameter passing in Java Sept 21, 2016 Sprenkle - CSCI209 1 Assignment 2 Review private int onevar; public Assign2(int par) { onevar = par;
More informationCOSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan
COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 A1 Posted over the weekend Two ques?ons (s?ll long ques?ons) Review of main concepts from COSC 111 Prac?ce coding
More informationJava. Package, Interface & Excep2on
Java Package, Interface & Excep2on Package 2 Package Java package provides a mechanism for par55oning the class name space into more manageable chunks Both naming and visibility control mechanism Define
More informationSept 26, 2016 Sprenkle - CSCI Documentation is a love letter that you write to your future self. Damian Conway
Objec,ves Javadocs Inheritance Ø Final methods, fields Abstract Classes Interfaces Sept 26, 2016 Sprenkle - CSCI209 1 JAVADOCS Documentation is a love letter that you write to your future self. Damian
More informationEncapsula)on CMSC 202
Encapsula)on CMSC 202 Types of Programmers Class creators Those developing new classes Want to build classes that expose the minimum interface necessary for the client program and hide everything else
More informationGenericity. Philippe Collet. Master 1 IFI Interna3onal h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314. P.
Genericity Philippe Collet Master 1 IFI Interna3onal 2013-2014 h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314 P. Collet 1 Agenda Introduc3on Principles of parameteriza3on Principles of genericity
More informationCOSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan
COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 Quick Review Inheritance models IS- A rela?onship Different from impor?ng classes Inherited classes can be organized
More informationInheritance, part 2: Subclassing. COMP 401, Spring 2015 Lecture 8 2/3/2015
Inheritance, part 2: Subclassing COMP 401, Spring 2015 Lecture 8 2/3/2015 Motivating Example lec8.ex1.v1 Suppose we re writing a university management system. Interfaces: Person get first and last name
More informationMo#va#ng the OO Way. COMP 401, Fall 2017 Lecture 05
Mo#va#ng the OO Way COMP 401, Fall 2017 Lecture 05 Arrays Finishing up from last #me Mul#dimensional Arrays Mul#dimensional array is simply an array of arrays Fill out dimensions lef to right. int[][]
More informationGeneric programming POLYMORPHISM 10/25/13
POLYMORPHISM Generic programming! Code reuse: an algorithm can be applicable to many objects! Goal is to avoid rewri:ng as much as possible! Example: int sqr(int i, int j) { return i*j; double sqr(double
More informationCOMP 401 Spring 2013 Midterm 1
COMP 401 Spring 2013 Midterm 1 I have not received nor given any unauthorized assistance in completing this exam. Signature: Name: PID: Please be sure to put your PID at the top of each page. This page
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 36 April 23, 2014 Overriding and Equality HW 10 has a HARD deadline Announcements You must submit by midnight, April 30 th Demo your project to your
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 21 March 17, 2014 Connec@ng OCaml to Java Announcements No Weirich OH today - > Wed 1-3PM instead Read Chapters 19-22 of the lecture notes HW07 available
More informationCREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed
CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?
More informationCSE 431S Type Checking. Washington University Spring 2013
CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks
More informationWhat is Inheritance?
Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting
More informationAgenda. Excep,ons Object oriented Python Library demo: xml rpc
Agenda Excep,ons Object oriented Python Library demo: xml rpc Resources h?p://docs.python.org/tutorial/errors.html h?p://docs.python.org/tutorial/classes.html h?p://docs.python.org/library/xmlrpclib.html
More informationCSSE 220. Interfaces and Polymorphism. Check out Interfaces from SVN
CSSE 220 Interfaces and Polymorphism Check out Interfaces from SVN Interfaces What, When, Why, How? What: Code Structure used to express operations that multiple class have in common No method implementations
More informationOOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.
OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every
More informationObject Oriented Design (OOD): The Concept
Object Oriented Design (OOD): The Concept Objec,ves To explain how a so8ware design may be represented as a set of interac;ng objects that manage their own state and opera;ons 1 Topics covered Object Oriented
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationChapter 6: Structural Design
Chapter 6: Structural Design Class Rela5onships Design alterna,ves for class use and reuse Composi5on Containment Inheritance Code Reuse Design Principles Rela5onships: Containment aka Holds- A subobjects
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationImplementing AddChoice()
Implementing AddChoice() The method will receive three parameters As usual for a class method the self parameter is required The text for the choice A Boolean deno9ng if it is the correct choice or not
More informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationArrays Classes & Methods, Inheritance
Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationType Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004
Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...
More informationCOSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan
COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 Quick Review Representa?ve example: Animal[] mypets = new Animal[4]; mypets[0] = new Dog(); mypets[1] = new Cat();
More informationArchitecture of so-ware systems
Architecture of so-ware systems Lecture 13: Class/object ini
More informationCOMP 401 Spring 2014 Midterm 1
COMP 401 Spring 2014 Midterm 1 I have not received nor given any unauthorized assistance in completing this exam. Signature: Name: PID: Please be sure to put your PID at the top of each page. This page
More informationRemedialJava Packages, Collec4ons, Inheritance 7/09/17. (remedial) Java. Packages. Anastasia Bezerianos 1
(remedial) Java anastasia.bezerianos@lri.fr Packages Anastasia Bezerianos 1 Packages (1) package path.to.package.foo;! Each class belongs to a package! Packages groups classes that serve a similar purpose.!
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More informationChapter 14 Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden
More informationObjec&ves. Packages Collec&ons Generics. Sept 28, 2016 Sprenkle - CSCI209 1
Objec&ves Packages Collec&ons Generics Sept 28, 2016 Sprenkle - CSCI209 1 PACKAGES Sept 28, 2016 Sprenkle - CSCI209 2 Packages Hierarchical structure of Java classes Ø Directories of directories java lang
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationObject Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming
Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in
More informationWritten by John Bell for CS 342, Spring 2018
Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors
More informationBBM 102 Introduc0on to Programming II Spring 2014
BBM 102 Introduc0on to Programming II Spring 2014 Encapsula0on Instructors: Fuat Akal, Nazlı İkizler Cinbiş, Oğuz Aslantürk TAs: Ahmet Selman Bozkır, Gültekin Işık, Levent Karacan 1 Today Informa0on Hiding
More information(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days
Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract
More informationCS 251 Intermediate Programming Inheritance
CS 251 Intermediate Programming Inheritance Brooke Chenoweth University of New Mexico Spring 2018 Inheritance We don t inherit the earth from our parents, We only borrow it from our children. What is inheritance?
More informationJava classes cannot extend multiple superclasses (unlike Python) but classes can implement multiple interfaces.
CSM 61B Abstract Classes & Interfaces Spring 2017 Week 5: February 13, 2017 1 An Appealing Appetizer 1.1 public interface Consumable { public void consume (); public abstract class Food implements Consumable
More informationLecture 2: Java & Javadoc
Lecture 2: Java & Javadoc CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Instance Variables or member variables or fields Declared in a class, but outside of any method, constructor or block
More information8.1 Inheritance. 8.1 Class Diagram for Words. 8.1 Words.java. 8.1 Book.java 1/24/14
8.1 Inheritance superclass 8.1 Class Diagram for Words! Inheritance is a fundamental technique used to create and organize reusable classes! The child is- a more specific version of parent! The child inherits
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationComputer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7
Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 1 Problem Ralph owns the Trinidad Fruit Stand that sells its fruit on the street, and he wants to use a computer
More informationAbstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.
a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must
More informationInheritance, Polymorphism, and Interfaces
Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)
More informationProgramming Environments
Programming Environments There are several ways of crea/ng a computer program Using an Integrated Development Environment (IDE) Using a text editor You should use the method you are most comfortable with.
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 21, 2013 Abstract
More informationUniversity of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Inheritance II Lecture 23, Thu Mar 30 2006 based on slides by Kurt Eiselt http://www.cs.ubc.ca/~tmm/courses/cpsc111-06-spr
More informationDay 4. COMP1006/1406 Summer M. Jason Hinek Carleton University
Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information
More informationSurvey #2. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Defining Interfaces Intro to Inheritance Readings This Week: Ch 9.4-9.5 and into Ch 10.1-10.8 (Ch 11.4-11.5 and into Ch 13 in old
More informationDesign Pa*erns. + Anima/on Undo/Redo Graphics and Hints
Design Pa*erns + Anima/on Undo/Redo Graphics and Hints Design Pa*erns Design: the planning that lays the basis for the making of every object or system Pa*ern: a type of theme of recurring events or objects
More informationOVERRIDING. 7/11/2015 Budditha Hettige 82
OVERRIDING 7/11/2015 (budditha@yahoo.com) 82 What is Overriding Is a language feature Allows a subclass or child class to provide a specific implementation of a method that is already provided by one of
More informationHistory of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995
Java Introduc)on History of Java Java was originally developed by Sun Microsystems star:ng in 1991 James Gosling Patrick Naughton Chris Warth Ed Frank Mike Sheridan This language was ini:ally called Oak
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More informationCS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)
CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 4: OO Principles - Polymorphism http://courses.cs.cornell.edu/cs2110/2018su Lecture 3 Recap 2 Good design principles.
More informationC++ Overview (1) COS320 Heejin Ahn
C++ Overview (1) COS320 Heejin Ahn (heejin@cs.princeton.edu) Introduc@on Created by Bjarne Stroustrup Standards C++98, C++03, C++07, C++11, and C++14 Features Classes and objects Operator overloading Templates
More informationProgramming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017
Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)
More informationObject Oriented Programming. Feb 2015
Object Oriented Programming Feb 2015 Tradi7onally, a program has been seen as a recipe a set of instruc7ons that you follow from start to finish in order to complete a task. That approach is some7mes known
More informationClasses, Objects, and OOP in Java. June 16, 2017
Classes, Objects, and OOP in Java June 16, 2017 Which is a Class in the below code? Mario itsame = new Mario( Red Hat? ); A. Mario B. itsame C. new D. Red Hat? Whats the difference? int vs. Integer A.
More informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationIntroduction to Inheritance
Introduction to Inheritance James Brucker These slides cover only the basics of inheritance. What is Inheritance? One class incorporates all the attributes and behavior from another class -- it inherits
More informationInheritance and Interfaces
Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical
More informationResearch opportuni/es with me
Research opportuni/es with me Independent study for credit - Build PL tools (parsers, editors) e.g., JDial - Build educa/on tools (e.g., Automata Tutor) - Automata theory problems e.g., AutomatArk - Research
More informationHAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.
HAS-A Relationship Association is a weak relationship where all objects have their own lifetime and there is no ownership. For example, teacher student; doctor patient. If A uses B, then it is an aggregation,
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationCSE Compilers. Reminders/ Announcements. Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013
CSE 401 - Compilers Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013 Winter 2013 UW CSE 401 (Michael Ringenburg) Reminders/ Announcements Project Part 2 due Wednesday Midterm Friday
More informationChapter 10 INHERITANCE 11/7/16 1
Chapter 10 INHERITANCE 11/7/16 1 Chapter Goals To learn about inheritance To implement subclasses that inherit and override superclass methods To understand the concept of polymorphism In this chapter,
More informationMore C++ : Vectors, Classes, Inheritance, Templates
Vectors More C++ : Vectors,, Inheritance, Templates vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes defined differently can be resized without explicit
More informationPROGRAMMING LANGUAGE 2
31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp-16/ Prof. Andrea Corradini Department of Computer Science, Pisa Control Flow Iterators Recursion Con>nua>ons Lesson 25! 1 Iterators
More informationLecture 10. Overriding & Casting About
Lecture 10 Overriding & Casting About Announcements for This Lecture Readings Sections 4.2, 4.3 Prelim, March 8 th 7:30-9:30 Material up to next Tuesday Sample prelims from past years on course web page
More informationObject Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia
Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing
More informationPOLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors
POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationInheritance and Encapsulation. Amit Gupta
Inheritance and Encapsulation Amit Gupta Project 1 How did it go? What did you like about it? What did you not like? What can we do to help? Suggestions Ask questions if you don t understand a concept
More informationQUESTIONS FOR AVERAGE BLOOMERS
MANTHLY TEST JULY 2017 QUESTIONS FOR AVERAGE BLOOMERS 1. How many types of polymorphism? Ans- 1.Static Polymorphism (compile time polymorphism/ Method overloading) 2.Dynamic Polymorphism (run time polymorphism/
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 25 November 1, 2017 Inheritance and Dynamic Dispatch (Chapter 24) Announcements HW7: Chat Client Available Soon Due: Tuesday, November 14 th at 11:59pm
More informationMore C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com
More C++ : Vectors, Classes, Inheritance, Templates with content from cplusplus.com, codeguru.com 2 Vectors vectors in C++ basically arrays with enhancements indexed similarly contiguous memory some changes
More informationCS/ENGRD 2110 SPRING Lecture 7: Interfaces and Abstract Classes
CS/ENGRD 2110 SPRING 2019 Lecture 7: Interfaces and Abstract Classes http://courses.cs.cornell.edu/cs2110 1 Announcements 2 A2 is due Thursday night (14 February) Go back to Lecture 6 & discuss method
More informationThe plan. Racket will return! Lecture will not recount every single feature of Java. Final project will be wri)ng a Racket interpreter in Java.
Introduc)on to Java The plan Racket will return! Final project will be wri)ng a Racket interpreter in Java. Lecture will not recount every single feature of Java. You may need to do some digging on your
More informationPOLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE
Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public
More information+ Abstract Data Types
Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract
More informationObject-oriented basics. Object Class vs object Inheritance Overloading Interface
Object-oriented basics Object Class vs object Inheritance Overloading Interface 1 The object concept Object Encapsulation abstraction Entity with state and behaviour state -> variables behaviour -> methods
More information