+ 8

26th Jan 2019, 8:28 AM
Vishal Shriwal
+ 20
28th Jan 2019, 6:28 AM
đMahesh Khatriđ
+ 8
POLYMORPHISM POLY MEANS MANY MORPHUS MEANS FORMS POLYMORPHISM MEANS MANYFORMS OR SEEING THE SAME THING IN MANY WAYS IS CALLED POLYMORPHISM THERE ARE TWO CONCEPTS OVERLOADING OVERRIDING OVERLOADING : METHOD NAME IS SAME BUT 1 NO OF PARAMTERS 2 ORDER OF PARAMETERS 3 SIZE OF PARAMETERS WILL BE DIFFERENT EXAMPLE 1 (METHOD) class Polygon { public void area(float r) { System.out.println(âArea = â + Math.PI*r*r); } public void area(int s) { System.out.println(âArea = â + s*s); } } class Oltest { public static void main(String args[]) { Polygon p=new Polygon(); p.area(2.25F); p.area(10); } } ======================== EXAMPLE 2 (CONSTRUCTOR) class Area { public Area(int l,int b) { System.out.println(âArea = â + l*b); } public Area(int s) { System.out.println(âArea = â + s*s); } } class Contest { public static void main(String args[]) { new Area(10,15); new Area(10); } } ======================== OVERRIDING METHOD IS SAME BUT IMPLEMENT IN ANOTHER CLASS OVERRIDING IS REQUIRED IF CHILD CLASS IS NOT SATISTYING WITH THE DEFINITION GIVEN BY PARENT CLASS SO CHILD WILL DEFINE ITS OWN CODE THIS IS CALLED OVERRIDING FOR OVERRIDING INHERITANCE IS NECESSARY THATS WHY POLYMORPHISM WILL BE FULFILLED ONLY WITH INHERITANCE EXAMPLE class Square { public void calculate(int s) { System.out.println(âSquare = â + s*s); } } class SqaureRoot extends Square { public void calculate(int s) { System.out.println(âSquareroot = â + Math.sqrt(s)); } } class Ortest { public static void main(String args[]) { Squareroot s= new Squareroot(); s.calculate(100); } }
26th Jan 2019, 4:56 PM
sree harsha
+ 4
Both are ways of achieving polymorphism... polymorphism means of many forms See https://googleweblight.com/i?u=https://stackoverflow.com/questions/7489335/overriding-vs-polymorphism&hl=en-KE
27th Jan 2019, 2:46 AM
Dan Rhamba
+ 3
Thanks for the info guys. đ
27th Jan 2019, 5:30 AM
Vishal Shriwal
+ 2
In Java, it is both. The first one is the well known overloading while the other one is runtime polymorphism which is implemented using method overriding.
27th Jan 2019, 3:23 AM
Infinity
29th Jan 2019, 2:47 AM
Vishal Shriwal
- 2
i dont know HaHaHAHaHa
28th Jan 2019, 9:54 AM
Zuhoruddin