Polymorphism is an important feature of object-oriented, it is simple to say: "An interface, a variety of implementations," is the same thing shows a variety of forms.
Here's a quick overview of the code:
Three conditions must be met to achieve polymorphism
1 must have inheritance
2 must be rewritten
3 Child class object must be referenced by parent class
public class Wine {
public void Fun1 () {
System.out.println ("The fun of Wine ...");
Fun2 ();
}
public void fun2 () {
System.out.println ("Wine Fun2 ...");
}
}
public class JNC extends wine{
/**
* @desc Subclasses overloads the parent class method
* The method does not exist in the parent class, and the parent class cannot reference the method after it has been transformed.
* @param a
* @return void
*/
public void Fun1 (String a) {
System.out.println ("JNC Fun1 ...");
Fun2 ();
}
/**
* Subclasses overriding parent class methods
* When referring to the parent class of a subclass called Fun2, the method must be called
*/
public void fun2 () {
System.out.println ("JNC Fun2 ...");
}
public static void Main (string[] args) {
Wine a = new JNC ();
A.fun1 ();
}
}
Polymorphism in Java