Java
Programming
Presentation
Md Robiul Islam
ID:22111102
Dept of CSE,BSFMSTU.
What is
Polymorphism ?
Poly
morphism
Many Forms
Examples of Polymorphism
Teache Studen
r t
Me
Friend
Same Objects Having Different
Behavior
Types of Polymorphism
Compile Time Run-Time
Method Method
Overloading Overriding
Method Overloading
public class A {
Whenever a class contain more
void add()
{ then one method with same
int a=10,b=20,sum=0; name and different type of
sum=a+b; parameters .
[Link](sum);
}
void add(int x,int y)
{
int sum=0; public static void main(String[] args) {
sum=x+y; A r= new A();
[Link](sum); [Link](); [Link](40, 50);
} [Link](50,45.32 );
void add(int x, double y) }
{
}
double sum=0;
sum=x+y; //Output:
[Link](sum); 30
}
90
94.32
Method Overriding
class shape{
Whenever we writing method in
void draw(){ super and sub classes in such a
way that method name and
[Link]("Can't say shape
type");
parameter must be same.
}
public class B {
} public static void main(String[] args)
class square extends shape{
{
@Override shape s = new square();
void draw() { [Link]();
}
[Link]();
[Link]("Square"); }
//Output :
}
}
Can't say shape type
Square
Thank You
All