Download presentation
Presentation is loading. Please wait.
1
Chapter 10 Thinking in Objects
2
Principle of OOP Inheritance Abstraction Encapsulation Polymorphism
Also know as (APIE)
3
Inheritance and Composition
A class can extend another class. Inheritance implements the “ IS a” relationship between objects A class can implements interface, methods members from its parent class.
4
Inheritance and Composition
Is- A and Has –A Inheritance VS Composition Favor Composition Polymorphism Interfaces
5
Is-A and Has-A relationship
Classes depend on another class Classes are related via Is –A or Has –A relationship Cat-> Animal = IS-A Car->Wheel, Engine =Has -A Train->Wheel,Engine=Has -A Car,Truck-> Vehicle= Is-A HAS-A=Composition (compose) IS-A=Inheritance(subtype) Reuse code
6
Inheritance (Is-A) Animal Cat
Animal is a base class cat class inheritances from animal Animal Cat
7
Inheritance Syntax Java Supports only public inheritance
A is a Superclass and B is a Subclass
8
Inheritance Syntax In order to call the constructor of
superclass(A) the keyword super is used
9
Composition (Has-A) car wheel Engine
Something is made up of other parts Car contains wheel and engine It is also called aggregation car wheel Engine
10
Composition (Has-A):aggregation
Composition(HAS-A) simply mean use of instance variables that are references to other objects. For example: Maruti has Engine, or House has Bathroom
11
Composition (Has-A):aggregation
12
Aggregation Lab
13
Inheritance Lab Follow the instructions provided on Lab9
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.