Object-Oriented Programming More Inheritance

Size: px
Start display at page:

Download "Object-Oriented Programming More Inheritance"

Transcription

1 Object-Oriented Programming More Inheritance Ewan Klein School of Informatics Inf1 :: 2009/10 Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 1 / 45

2 1 Inheritance Flat Hierarchy Layered Hierarchy 2 Polymorphism 3 Overriding and Overloading 4 Abstract Classes 5 Recap Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 2 / 45

3 Flat Animal Hierarchy Animal sleep() makenoise() roam() Lion Wolf makenoise() Cat makenoise() Dog makenoise() makenoise() Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 3 / 45

4 Animals Example, 1 Our base class: Animal Animal public class Animal { public void sleep() { Systemoutprintln( Sleeping: Zzzzz ); public void makenoise() { Systemoutprintln( Noises ); public void roam() { Systemoutprintln( Roamin on the plain ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 4 / 45

5 Animals Example, 2 1 Lion IS-A Animal 2 Override the makenoise() method Lion public class Lion extends Animal { public void makenoise() { Systemoutprintln( Roaring: Rrrrrr! ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 5 / 45

6 Animals Example, 3 1 Cat IS-A Animal 2 Override the makenoise() method Cat public class Cat extends Animal { public void makenoise() { Systemoutprintln( Miaowing: Miaooo! ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 6 / 45

7 Animals Example, 4 1 Wolf IS-A Animal 2 Override the makenoise() method Wolf public class Wolf extends Animal { public void makenoise() { Systemoutprintln( Howling: Ouooooo! ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 7 / 45

8 Animals Example, 5 1 Dog IS-A Animal 2 Override the makenoise() method Dog public class Dog extends Animal { public void makenoise() { Systemoutprintln( Barking: Woof Woof! ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 8 / 45

9 Animals Example, 6 The Launcher public class AnimalLauncher { public static void main(string[] args) { Systemoutprintln( \nwolf\n===== ); Wolf wolfie = new Wolf(); wolfiemakenoise() ; // from Wolf wolfieroam(); // from Animal wolfiesleep(); // from Animal Systemoutprintln( \nlion\n===== ); Lion leo = new Lion(); leomakenoise(); // from Lion leoroam(); // from Animal leosleep(); // from Animal Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 9 / 45

10 Animals Example, 7 Output Wolf ===== Howling: Ouooooo! Roamin on the plain Sleeping: Zzzzz Lion ===== Roaring: Rrrrrr! Roamin on the plain Sleeping: Zzzzz Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 10 / 45

11 Nested Animal Hierarchy Lions and cats can be grouped together into Felines, with common roam() behaviours Dogs and wolves can be grouped together into Canines, with common roam() behaviours Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 11 / 45

12 Nested Animal Hierarchy Animal sleep() makenoise() roam() Feline roam() Canine roam() Lion makenoise() Cat makenoise() Wolf makenoise() Dog makenoise() Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 12 / 45

13 Animals Example, 1 Same as before Animal public class Animal { public void sleep() { Systemoutprintln( Sleeping: Zzzzz ); public void makenoise() { Systemoutprintln( Noises ); public void roam() { Systemoutprintln( Roamin on the plain ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 13 / 45

14 Animals Example, 2 The new class Feline Feline public class Feline extends Animal { public void roam() { // Override roam() Systemoutprintln( Roaming: I m roaming alone ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 14 / 45

15 Animals Example, 3 The new class Canine Canine public class Canine extends Animal { public void roam() { // Override roam() Systemoutprintln( Roaming: I m with my pack ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 15 / 45

16 Animals Example, 4 1 Lion IS-A Feline 2 Override the makenoise() method Lion public class Lion extends Feline { public void makenoise() { Systemoutprintln( Roaring: Rrrrrr! ); Similarly for Cat Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 16 / 45

17 Animals Example, 5 1 Wolf IS-A Canine 2 Override the makenoise() method Wolf public class Wolf extends Canine { public void makenoise() { Systemoutprintln( Howling: Ouooooo! ); Similarly for Dog Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 17 / 45

18 Which method gets called? Animal sleep() makenoise() roam() 1 Wolf wolfie = new Wolf(); 2 wolfiemakenoise(); 3 wolfieroam(); Canine roam() 4 wolfiesleep(); Wolf makenoise() Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 18 / 45

19 Animals Example, 6 The Launcher public class AnimalLauncher { public static void main(string[] args) { Systemoutprintln( \nwolf\n===== ); Wolf wolfie = new Wolf(); wolfiemakenoise(); // from Wolf wolfieroam(); // from Canine wolfiesleep(); // from Animal Systemoutprintln( \nlion\n===== ); Lion leo = new Lion(); leomakenoise(); // from Lion leoroam(); // from Feline leosleep(); // from Animal Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 19 / 45

20 Animals Example, 7 Output Wolf ===== Howling: Ouooooo! Roaming: I m with my pack Sleeping: Zzzzz Lion ===== Roaring: Rrrrrr! Roaming: I m roaming alone Sleeping: Zzzzz Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 20 / 45

21 Typing and Polymorphism polymorphism (= many shapes ): the same piece of code can be assigned multiple types A class defines a type, namely the signatures of its methods S is a subtype of T, written S <: T, if a value of type S can be used in any context where a value of type T is expected The relation <: is reflexive: T <: T The relation <: is transitive: if S <: T and T <: U, then S <: U NB: We say T is a supertype of S if S is a subtype of T Inclusion polymorphism: objects of different types S1, S2, may be treated uniformly as instances of a common supertype T Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 21 / 45

22 Declaring and Initializing a Reference Variable create a Wolf object Wolf wolfie = new Wolf(); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 22 / 45

23 Declaring and Initializing a Reference Variable declare a reference variable Wolf wolfie = new Wolf(); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 23 / 45

24 Declaring and Initializing a Reference Variable link the object to the reference Wolf wolfie = new Wolf(); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 24 / 45

25 Declaring and Initializing a Reference Variable supertype object of subtype Animal wolfie = new Wolf(); Reference type can be supertype of the object type Eg, Wolf <: Animal Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 25 / 45

26 Polymorphic ArrayList The Launcher public class AnimalLauncher2 { public static void main(string[] args) { Wolf wolfie = new Wolf(); Lion leo = new Lion(); Cat felix = new Cat(); Dog rover = new Dog(); ArrayList< Animal > animals = new ArrayList<Animal>(); animalsadd(wolfie); animalsadd(leo); animalsadd(felix); animalsadd(rover); for ( Animal a : animals) { amakenoise(); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 26 / 45

27 Polymorphic Arrays ArrayList<Animal> is polymorphic animalsadd(wolfie) add an object of type Wolf OK since Wolf <: Animal for (Animal a : animals) for each object a of type T such that T <: Animal amakenoise() if a is of type T, use T s makenoise() method Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 27 / 45

28 Method Overriding, 1 If a class C overrides a method m of superclass D, then: Parameter lists must be same and return type must be compatible: 1 signature of m in C must be same as signature of m in D; ie same name, same parameter list, and 2 return type S of m in C must such that S <: T, where T is return type of m in D m must be at least as accessible in C as m is in D Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 28 / 45

29 Method Overriding, 2 method in Animal public void makenoise() { Wrong: method in Wolf public void makenoise( int volume ) { Wrong: method in Wolf private void makenoise() { Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 29 / 45

30 Method Overloading, 1 Overloading: two methods with same name but different parameter lists Overloaded makenoise public void makenoise() { public void makenoise(int volume) { Overloaded println Systemoutprintln(3); // int Systemoutprintln(30); // double Systemoutprintln((float) 30); // cast to float Systemoutprintln( 30 ); // String Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 30 / 45

31 Method Overloading, 2 1 Return types can be different 2 You can t just change the return type gets treated as an invalid override 3 Access levels can be varied up or down Incorrect override of makenoise public String makenoise() { String howl = Ouooooo! ; return howl; Exception in thread main javalangerror: Unresolved compilation problem: The return type is incompatible with AnimalmakeNoise() at week06wolfmakenoise(wolfjava:15) at week06animallaunchermain(animallauncherjava:11) Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 31 / 45

32 Animal Objects? Creating new objects Wolf wolfie = new Wolf(); Animal leo = new Lion(); Animal weird = new Animal(); Animal class is meant to contain information that all animals have in common But this is not enough to define any one specific animal Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 32 / 45

33 Concrete vs Abstract Concrete Abstract Examples: Cat, Wolf Specific enough to be instantiated Examples: Animal, Feline Not intended to have instances Only useful if extended Any instances will have to be instances of a subclass of the abstract class Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 33 / 45

34 The Abstract Animal, 1 Animal abstract class Animal { public void sleep() { Systemoutprintln( Sleeping: Zzzzz ); public void makenoise() { Systemoutprintln( Noises ); public void roam() { Systemoutprintln( Roamin on the plain ); Just put the keyword abstract before the class declaration Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 34 / 45

35 The Abstract Animal, 2 An abstract class can be extended by other abstract classes Canine and Feline can (and should) both be abstract Animal abstract class Animal { public void sleep() { Systemoutprintln( Sleeping: Zzzzz ); public void makenoise() { Systemoutprintln( Noises ); public void roam() { Systemoutprintln( Roamin on the plain ); Just put the keyword abstract before the class declaration Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 35 / 45

36 The Abstract Animal, 2 Animal abstract class Animal { public void sleep() { Systemoutprintln( Sleeping: Zzzzz ); public abstract void roam(); public abstract void makenoise(); Now has abstract methods! Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 36 / 45

37 The Abstract Animal, 3 roam() and makenoise() are abstract methods (we ve already seen these in interfaces): no body; must be implemented in any concrete subclass (implemented overriden); don t have to be implemented by an abstract subclass; can only be declared in an abstract class; sleep() is not abstract, so can be straightforwardly inherited Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 37 / 45

38 Abstract Classes in Animal Hierarchy <<Abstract>> Animal sleep() makenoise() roam() <<Abstract>> roam() Feline <<Abstract>> roam() Canine Lion makenoise() Cat makenoise() Wolf makenoise() Dog makenoise() Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 38 / 45

39 Using Abstract Classes Use an abstract class when you have several similar classes that: have a lot in common the implemented parts of the abstract class have some differences the abstract methods Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 39 / 45

40 Digression: Constructor Chaining Constructor of the immediate superclass invoked with super() If you don t explicitly call this, the compiler will Case 1 No constructor explicitly declared Compiler inserts public Foo() { super(); Case 2 You have already declared one or more constructors Compiler inserts the following as first statement in each one: super(); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 40 / 45

41 Recap: Implementing/Overriding, 1 If a class C implements or overrides a method m of superclass D, then: Parameter lists must be same and return type must be compatible: 1 signature of m in C must be same as signature of m in D; ie same name, same parameter list, and 2 return type S of m in C must such that S <: T, where T is return type of m in D Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 41 / 45

42 Method Implementation, 1 Abstract method in Animal public abstract void makenoise(); Wrong: method in Wolf public void makenoise( int volume ) { Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 42 / 45

43 Method Overloading Overloading: two methods with same name but different parameter lists Overloaded makenoise public void makenoise(int volume) { public void makenoise() { makenoise(int 1); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 43 / 45

44 Method Implementation, 2 You cannot implement or override a method by providing just an overloaded method Declaration of sleep() in Animal public void sleep() { Systemoutprintln( Sleeping: Zzzzz ); Right: overriding sleep() in Wolf public void sleep() { Systemoutprintln( Sleeping: XXXXX ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 44 / 45

45 Method Implementation, 3 Wrong: overloading sleep() in Wolf public void sleep(int duration) { String sleepnoise = Sleeping: Zzzzz ; if (duration > 2) sleepnoise = Still Sleeping: XXXXX ; Systemoutprintln(sleepNoise); Right: overloading and overriding public void sleep(int duration) { public void sleep() { Systemoutprintln( Sleeping: XXXXX ); Ewan Klein (School of Informatics) OOP: More Inheritance Inf1 :: 2009/10 45 / 45

Object-Oriented ProgrammingInheritance & Polymorphism

Object-Oriented ProgrammingInheritance & Polymorphism Inheritance Polymorphism Overriding and Overloading Object-Oriented Programming Inheritance & Polymorphism Inf1 :: 2008/09 Inheritance Polymorphism Overriding and Overloading 1 Inheritance Flat Hierarchy

More information

Inf1-OP. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. March 12, School of Informatics

Inf1-OP. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. March 12, School of Informatics Inf1-OP Inheritance Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 12, 2018 UML Class Diagrams UML: language for specifying and visualizing OOP software

More information

Inf1-OP. Classes with Stuff in Common. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein.

Inf1-OP. Classes with Stuff in Common. Inheritance. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. Inf1-OP Inheritance UML Class Diagrams UML: language for specifying and visualizing OOP software systems UML class diagram: specifies class name, instance variables, methods,... Volker Seeker, adapting

More information

Inf1-OOP. Inheritance and Interfaces. Ewan Klein, Perdita Stevens. January 12, School of Informatics

Inf1-OOP. Inheritance and Interfaces. Ewan Klein, Perdita Stevens. January 12, School of Informatics Inf1-OOP Inheritance and Interfaces Ewan Klein, Perdita Stevens School of Informatics January 12, 2013 Encapsulation Again Inheritance Encapsulation and Inheritance The Object Superclass Flat vs. Nested

More information

Encapsulation. Inf1-OOP. Getters and Setters. Encapsulation Again. Inheritance Encapsulation and Inheritance. The Object Superclass

Encapsulation. Inf1-OOP. Getters and Setters. Encapsulation Again. Inheritance Encapsulation and Inheritance. The Object Superclass Encapsulation Again Inheritance Encapsulation and Inheritance Inf1-OOP Inheritance and Interfaces Perdita Stevens, adapting earlier version by Ewan Klein School of Informatics March 9, 2015 The Object

More information

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed

COMP200 INTERFACES. OOP using Java, from slides by Shayan Javed 1 1 COMP200 INTERFACES OOP using Java, from slides by Shayan Javed Interfaces 2 ANIMAL picture food sleep() roam() makenoise() eat() 3 ANIMAL picture food sleep() roam() makenoise() eat() 4 roam() FELINE

More information

Object Oriented Programming Part II of II. Steve Ryder Session 8352 JSR Systems (JSR)

Object Oriented Programming Part II of II. Steve Ryder Session 8352 JSR Systems (JSR) Object Oriented Programming Part II of II Steve Ryder Session 8352 JSR Systems (JSR) sryder@jsrsys.com New Terms in this Section API Access Modifier Package Constructor 2 Polymorphism Three steps of object

More information

Inheritance & Polymorphism. Object-Oriented Programming

Inheritance & Polymorphism. Object-Oriented Programming Inheritance & Polymorphism Object-Oriented Programming Outline Example Design an inheritance structure IS-A and HAS-A Polymorphism protected access level Rules for overriding the Object class Readings:

More information

Java Session. Day 2. Reference: Head First Java

Java Session. Day 2. Reference: Head First Java Java Session Day 2 shrishty_bcs11@nitc.ac.in Reference: Head First Java Encapsulation This hides the data!! How do we do it? By simply using public private access modifiers. 1. Mark the instance variables

More information

Software Development (cs2500)

Software Development (cs2500) Software Development (cs2500) Lecture 31: Abstract Classes and Methods M.R.C. van Dongen January 12, 2011 Contents 1 Outline 1 2 Abstract Classes 1 3 Abstract Methods 3 4 The Object Class 4 4.1 Overriding

More information

Practice for Chapter 11

Practice for Chapter 11 Practice for Chapter 11 MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Object-oriented programming allows you to derive new classes from existing

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument 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 information

MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011

MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011 MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011 1 Goals of the Lecture Continue a review of fundamental object-oriented concepts 2 Overview of OO Fundamentals

More information

Chapter 14 Abstract Classes and Interfaces

Chapter 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 information

Inheritance & Polymorphism

Inheritance & Polymorphism Inheritance & Polymorphism Procedural vs. object oriented Designing for Inheritance Test your Design Inheritance syntax **Practical ** Polymorphism Overloading methods Our First Example There will be shapes

More information

OOP in Java Review. CS356 Object-Oriented Design and Programming October 1, 2014

OOP in Java Review. CS356 Object-Oriented Design and Programming   October 1, 2014 OOP in Java Review CS356 Object-Oriented Design and Programming http://cs356.yusun.io October 1, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Announcement Submit your GitHub username as soon

More information

First IS-A Relationship: Inheritance

First IS-A Relationship: Inheritance First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class

More information

What is Inheritance?

What 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 information

More About Objects. Zheng-Liang Lu Java Programming 255 / 282

More About Objects. Zheng-Liang Lu Java Programming 255 / 282 More About Objects Inheritance: passing down states and behaviors from the parents to their children. Interfaces: requiring objects for the demanding methods which are exposed to the outside world. Polymorphism

More information

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel)

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel) Programmieren II Polymorphism Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from T. Bögel) June 4, 2014 1 / 50 Outline 1 Recap - Collections 2 Advanced OOP: Polymorphism Polymorphism

More information

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007 Object Fundamentals Part Three Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations

More information

Polymorphism. Arizona State University 1

Polymorphism. Arizona State University 1 Polymorphism CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 15 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

More OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012

More OO Fundamentals. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012 More OO Fundamentals CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 4 09/11/2012 1 Goals of the Lecture Continue a review of fundamental object-oriented concepts 2 Overview of OO Fundamentals

More information

More Relationships Between Classes

More Relationships Between Classes More Relationships Between Classes Inheritance: passing down states and behaviors from the parents to their children Interfaces: grouping the methods, which belongs to some classes, as an interface to

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

HAS-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. 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 information

Programming Using C# QUEEN S UNIVERSITY BELFAST. Practical Week 7

Programming Using C# QUEEN S UNIVERSITY BELFAST. Practical Week 7 Programming Using C# QUEEN S UNIVERSITY BELFAST Practical Week 7 Table of Contents PRACTICAL 7... 2 EXERCISE 1... 2 TASK 1: Zoo Park (Without Inheritance)... 2 TASK 2: Zoo Park with Inheritance... 5 TASK

More information

HAS-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. 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 information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. 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 information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

C18a: Abstract Class and Method

C18a: Abstract Class and Method CISC 3115 TY3 C18a: Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/31/2018 CUNY Brooklyn College 1 Outline Recap Inheritance and polymorphism Abstract

More information

COMP 110/L Lecture 20. Kyle Dewey

COMP 110/L Lecture 20. Kyle Dewey COMP 110/L Lecture 20 Kyle Dewey Outline super in methods abstract Classes and Methods Polymorphism super in Methods Recap You ve seen super in constructors... Recap You ve seen super in constructors...

More information

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object Oriented Programming. Java-Lecture 11 Polymorphism Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class

More information

OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK. COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK

OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK. COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK Mock Exam 2010 Second Year Computer Science CS2500: Software Development Dr Mock

More information

Inheritance (Outsource: )

Inheritance (Outsource: ) (Outsource: 9-12 9-14) is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, inherit attributes and behavior of the pre-existing classes,

More information

Object Orientated Programming Details COMP360

Object Orientated Programming Details COMP360 Object Orientated Programming Details COMP360 The ancestor of every action is a thought. Ralph Waldo Emerson Three Pillars of OO Programming Inheritance Encapsulation Polymorphism Inheritance Inheritance

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 22 Polymorphism using Interfaces Overview Problem: Can we delay decisions regarding which method to use until run time? Polymorphism Different methods

More information

COE318 Lecture Notes Week 8 (Oct 24, 2011)

COE318 Lecture Notes Week 8 (Oct 24, 2011) COE318 Software Systems Lecture Notes: Week 8 1 of 17 COE318 Lecture Notes Week 8 (Oct 24, 2011) Topics == vs..equals(...): A first look Casting Inheritance, interfaces, etc Introduction to Juni (unit

More information

Programming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism

Programming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism Programming using C# LECTURE 07 Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism What is Inheritance? A relationship between a more general class, called the base class

More information

Software Practice 1 - Inheritance and Interface Inheritance Overriding Polymorphism Abstraction Encapsulation Interfaces

Software Practice 1 - Inheritance and Interface Inheritance Overriding Polymorphism Abstraction Encapsulation Interfaces Software Practice 1 - Inheritance and Interface Inheritance Overriding Polymorphism Abstraction Encapsulation Interfaces Prof. Hwansoo Han T.A. Minseop Jeong T.A. Wonseok Choi 1 In Previous Lecture We

More information

Java Object Oriented Design. CSC207 Fall 2014

Java 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 information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 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 information

Create a Java project named week10

Create a Java project named week10 Objectives of today s lab: Through this lab, students will examine how casting works in Java and learn about Abstract Class and in Java with examples. Create a Java project named week10 Create a package

More information

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring

More information

CSA 1019 Imperative and OO Programming

CSA 1019 Imperative and OO Programming CSA 1019 Imperative and OO Programming Object Oriented III Mr. Charlie Abela Dept. of of Artificial Intelligence Objectives Getting familiar with Method Overriding Polymorphism Overriding Vs Vs Overloading

More information

C10: Garbage Collection and Constructors

C10: Garbage Collection and Constructors CISC 3120 C10: Garbage Collection and Constructors Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/5/2018 CUNY Brooklyn College 1 Outline Recap OOP in Java: composition &

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes

More information

index.pdf January 21,

index.pdf January 21, index.pdf January 21, 2013 1 ITI 1121. Introduction to Computing II Circle Let s complete the implementation of the class Circle. Marcel Turcotte School of Electrical Engineering and Computer Science Version

More information

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012)

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012) COE318 Lecture Notes: Week 9 1 of 14 COE318 Lecture Notes Week 9 (Week of Oct 29, 2012) Topics The final keyword Inheritance and Polymorphism The final keyword Zoo: Version 1 This simple version models

More information

Lecture 4: Extending Classes. Concept

Lecture 4: Extending Classes. Concept Lecture 4: Extending Classes Concept Inheritance: you can create new classes that are built on existing classes. Through the way of inheritance, you can reuse the existing class s methods and fields, and

More information

After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady.

After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady. Introduction After a lecture on cosmology and the structure of the solar system, William James was accosted by a little old lady. Your theory that the sun is the centre of the solar system, and the earth

More information

CS 61B Discussion 4: Inheritance Fall 2018

CS 61B Discussion 4: Inheritance Fall 2018 CS 61B Discussion 4: Inheritance Fall 2018 1 Creating Cats Given the Animal class, fill in the definition of the Cat class so that it makes a "Meow!" noise when greet() is called. Assume this noise is

More information

HAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.

HAS-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 information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance (part II) Polymorphism Version of January 21, 2013 Abstract These lecture notes

More information

Object-Oriented Programming

Object-Oriented Programming Abstract classes Object-Oriented Programming Outline Abstract classes Abstract methods Design pattern: Template method Dynamic & static binding Upcasting & Downcasting Readings: HFJ: Ch. 8. GT: Ch. 8.

More information

Object Oriented Programming: Based on slides from Skrien Chapter 2

Object Oriented Programming: Based on slides from Skrien Chapter 2 Object Oriented Programming: A Review Based on slides from Skrien Chapter 2 Object-Oriented Programming (OOP) Solution expressed as a set of communicating objects An object encapsulates the behavior and

More information

OVERRIDING. 7/11/2015 Budditha Hettige 82

OVERRIDING. 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 information

Object-Oriented Programming Classes, Objects, Variables

Object-Oriented Programming Classes, Objects, Variables Object-Oriented Programming Classes, Objects, Variables Ewan Klein School of Informatics Inf1 :: 2009/10 Ewan Klein (School of Informatics) Object-Oriented ProgrammingClasses, Objects, Variables Inf1 ::

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 4 09/03/2009

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 4 09/03/2009 Object Fundamentals Part Three Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 4 09/03/2009 1 Lecture Goals Continue our tour of the basic concepts, terminology, and notations

More information

Questions Answer Key Questions Answer Key Questions Answer Key

Questions Answer Key Questions Answer Key Questions Answer Key Benha University Term: 2 nd (2013/2014) Class: 2 nd Year Students Subject: Object Oriented Programming Faculty of Computers & Informatics Date: 26/4/2014 Time: 1 hours Exam: Mid-Term (A) Name:. Status:

More information

CS Programming I: Inheritance

CS Programming I: Inheritance CS 200 - Programming I: Inheritance Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Inheritance

More information

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G INHERITANCE & POLYMORPHISM P2 LESSON 12 P2 LESSON 12.1 INTRODUCTION inheritance: OOP allows a programmer to define new classes

More information

ITI Introduction to Computing II

ITI 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 information

15CS45 : OBJECT ORIENTED CONCEPTS

15CS45 : OBJECT ORIENTED CONCEPTS 15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?

More information

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Abstract 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 information

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School

Class Hierarchy and Interfaces. David Greenstein Monta Vista High School Class Hierarchy and Interfaces David Greenstein Monta Vista High School Inheritance Inheritance represents the IS-A relationship between objects. an object of a subclass IS-A(n) object of the superclass

More information

Chapter 5. Inheritance

Chapter 5. Inheritance Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism through Method Overriding Learn the keywords : super

More information

COMP 250 Fall inheritance Nov. 17, 2017

COMP 250 Fall inheritance Nov. 17, 2017 Inheritance In our daily lives, we classify the many things around us. The world has objects like dogs and cars and food and we are familiar with talking about these objects as classes Dogs are animals

More information

Inheritance, Polymorphism, and Interfaces

Inheritance, 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 information

C09: Interface and Abstract Class and Method

C09: Interface and Abstract Class and Method CISC 3120 C09: Interface and Abstract Class and Method Hui Chen Department of Computer & Information Science CUNY Brooklyn College 9/28/2017 CUNY Brooklyn College 1 Outline Recap Polymorphism In-class

More information

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either

More information

CS 251 Intermediate Programming Inheritance

CS 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 information

Inheritance. Transitivity

Inheritance. 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 information

ITI Introduction to Computing II

ITI 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 information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Inheritance (continued) Inheritance

Inheritance (continued) Inheritance Objectives Chapter 11 Inheritance and Polymorphism Learn about inheritance Learn about subclasses and superclasses Explore how to override the methods of a superclass Examine how constructors of superclasses

More information

C++ Inheritance and Encapsulation

C++ Inheritance and Encapsulation C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members

More information

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008 Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object

More information

Binghamton University. CS-140 Fall Dynamic Types

Binghamton University. CS-140 Fall Dynamic Types Dynamic Types 1 Assignment to a subtype If public Duck extends Bird { Then, you may code:. } Bird bref; Duck quack = new Duck(); bref = quack; A subtype may be assigned where the supertype is expected

More information

CMSC 202. Generics II

CMSC 202. Generics II CMSC 202 Generics II Generic Sorting We can now implement sorting functions that can be used for any class (that implements Comparable). The familiar insertion sort is shown below.!! public static

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011

UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011 UML & OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 3 08/30/2011 1 Goals of the Lecture Review the material in Chapter 2 of the Textbook Cover key parts of the UML notation

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt

More information

Generalized Code. Fall 2011 (Honors) 2

Generalized Code. Fall 2011 (Honors) 2 CMSC 202H Generics Generalized Code One goal of OOP is to provide the ability to write reusable, generalized code. Polymorphic code using base classes is general, but restricted to a single class hierarchy

More information

Records. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05

Records. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05 Records CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 15: Objects 25 Feb 05 Objects combine features of records and abstract data types Records = aggregate data structures Combine several

More information

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance? CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 5: Inheritance & Polymorphism Lecture Contents 2 What is Inheritance? Super-class & sub class Protected members Creating subclasses

More information

OOPs 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. 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 information

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course : Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order

More information

Making New instances of Classes

Making New instances of Classes Making New instances of Classes NOTE: revised from previous version of Lecture04 New Operator Classes are user defined datatypes in OOP languages How do we make instances of these new datatypes? Using

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object 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 information

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. Inheritance in Java 1. Inheritance 2. Types of Inheritance 3. Why multiple inheritance is not possible in java in case of class? Inheritance in java is a mechanism in which one object acquires all the

More information

Exercise: Singleton 1

Exercise: Singleton 1 Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance

More information

Building custom components IAT351

Building custom components IAT351 Building custom components IAT351 Week 1 Lecture 1 9.05.2012 Lyn Bartram lyn@sfu.ca Today Review assignment issues New submission method Object oriented design How to extend Java and how to scope Final

More information

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

Example: Count of Points

Example: Count of Points Example: Count of Points 1 public class Point { 2... 3 private static int numofpoints = 0; 4 5 public Point() { 6 numofpoints++; 7 } 8 9 public Point(int x, int y) { 10 this(); // calling Line 5 11 this.x

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 5: Inheritance & Polymorphism Lecture Contents 2 What is Inheritance? Super-class & sub class Protected members Creating subclasses

More information

C11: Garbage Collection and Constructors

C11: Garbage Collection and Constructors CISC 3120 C11: Garbage Collection and Constructors Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/5/2017 CUNY Brooklyn College 1 Outline Recap Project progress and lessons

More information