Polymorphism inward Java
Polymorphism means, beingness of Object behaviour inward many forms
There are 2 types of Polymorphism
i) Compile Time Polymorphism / Static binding / Method overloading
ii) Run Time Polymorphism / Dynamic binding / Method overriding
------------------------------------------
i) Compile Time Polymorphism
If 2 or to a greater extent than methods having same refer inward the same bird merely they differ inward the next ways.
i) Number of Arguments
ii) Type of Arguments
Example:
public bird MethodOverloading {
world void add(int a, int b){
System.out.println(a+b);
}
world void add(int a, int b, int c){
System.out.println(a+b+c);
}
world void add(double a, double b){
System.out.println(a+b);
}
world void add(double a, double b, double c){
System.out.println(a+b+c);
}
world static void primary (String [] args){
MethodOverloading obj = novel MethodOverloading();
obj.add(10, 20);
obj.add(10, 20, 30);
obj.add(1.2345, 2.3456);
obj.add(1.2345, 2.3456, 4.45678);
}
}
-----------------------------------------
ii) Run Time Polymorphism
If 2 or to a greater extent than methods having same refer as well as same arguments available inward the super bird as well as sub class.
Example:
Class 1
public bird Influenza A virus subtype H5N1 {
public void addition(int a, int b) {
System.out.println(a+b);
}
public static void primary (String [] args){
Influenza A virus subtype H5N1 myObject = novel A();
myObject.addition(10, 20);//30
}
}
------------------------------
Class 2:
public bird B extends Influenza A virus subtype H5N1 {
world void addition(int a, int b) {
System.out.println(a+b);
}
public static void primary (String [] args){
Influenza A virus subtype H5N1 obj1 = novel Influenza A virus subtype H5N1 ();
obj1.addition(10, 20); //30
B obj2 = novel B();
obj2.addition(40, 50);//90
}
}
--------------------------------------------------
Polymorphism means, beingness of Object behaviour inward many forms
There are 2 types of Polymorphism
i) Compile Time Polymorphism / Static binding / Method overloading
ii) Run Time Polymorphism / Dynamic binding / Method overriding
------------------------------------------
i) Compile Time Polymorphism
If 2 or to a greater extent than methods having same refer inward the same bird merely they differ inward the next ways.
i) Number of Arguments
ii) Type of Arguments
Example:
public bird MethodOverloading {
world void add(int a, int b){
System.out.println(a+b);
}
world void add(int a, int b, int c){
System.out.println(a+b+c);
}
world void add(double a, double b){
System.out.println(a+b);
}
world void add(double a, double b, double c){
System.out.println(a+b+c);
}
world static void primary (String [] args){
MethodOverloading obj = novel MethodOverloading();
obj.add(10, 20);
obj.add(10, 20, 30);
obj.add(1.2345, 2.3456);
obj.add(1.2345, 2.3456, 4.45678);
}
}
-----------------------------------------
ii) Run Time Polymorphism
If 2 or to a greater extent than methods having same refer as well as same arguments available inward the super bird as well as sub class.
Example:
Class 1
public bird Influenza A virus subtype H5N1 {
public void addition(int a, int b) {
System.out.println(a+b);
}
public static void primary (String [] args){
Influenza A virus subtype H5N1 myObject = novel A();
myObject.addition(10, 20);//30
}
}
------------------------------
Class 2:
public bird B extends Influenza A virus subtype H5N1 {
world void addition(int a, int b) {
System.out.println(a+b);
}
public static void primary (String [] args){
Influenza A virus subtype H5N1 obj1 = novel Influenza A virus subtype H5N1 ();
obj1.addition(10, 20); //30
B obj2 = novel B();
obj2.addition(40, 50);//90
}
}
--------------------------------------------------