OOPS-1
OOPS-1
Polymorphism
Wlrtual/Qveridling
Method
Method Operato
Overloading Overloding
2
Inheritance and Polymorphism
Java_-_Inhe..orphism.pdf Open
Static Polymorphism
Also called compile time polymorphism.
Class can have more than one methods with same name but different number or sequence or
type of arguments.
Type of the object is determined at compile time(by the compiler). Known as static binding.
3
Inheritance and Polymorphism
Method Overloading
void test (){
methods within the same class that share the System.out .print ln ( "No parameters ");
same name, but their parameter declarations
are different
1/ Overload test for one integer parameter.
compile time polymorphism implementation of void test (int a) {
java System. out.println ("a: a) ;
depth-d;
Animal
4
Non-ttying
bird
Flying
Reptile
bird
Single Inheritance
Vehicle
Class A Base Class
Extends Car
Single Inheritance
Multi-Level Inheritance
" Inthis inheritance, a derived class is created from another derived class.
Class A Student
Marks
Class B
CassC Sports
Hierarchical Inheritance
The hybrid inheritance can be achieved by using the following combinations:
Single and Multiple Inheritance (not supported but can be achieved through interface)
" Muitilevel and Hierarchical Inheritance
Father
inherit Hierarchical
inheritance
Son Daughter
Hybrid
Inheritance
Hybrid Inheritance
Multiple Inheritance
" In this inheritance, a derived class is created What is Diamond Problem?
from more than one base class. Java does
not support multiple inheritance.
In multiple inheritance there is a chance of Class A
Class B ee Class C
Class D
Inheritance - Advantages and Disadvantages
" Advantages of Inheritance
" inheritance - It can make application code more flexible to change because classes that inherit
form a common superclass can be used interchangeably.
Reusability - Facility to use public methods of base class without rewriting the same.
Extensibility -Extending the base class logic as per business logic of the derived class.
Disadvantages of lnheritance
" It increase's timefeffort to take the program to jump through all the leveis of inherited classes.
" Main Disadvantage of Using inheritance is that the two classes(base and inherited class) get
tightly coupled.