1. Polymorphism: Features that have the ability to express multiple forms
Parent class:
Public abstract class Animal {
public abstract void Say ();
}
Sub-class:
public class Dog extends Animal {
@Override
public void Say () {
System.out.println ("dog");
}
}
public class Cat extends animal{
@Override
public void Say () {
System.out.println ("Cat");
}
}
So you can override the abstract say () method in the parent class
2. If you convert a reference variable to a subclass type, it is called a downward transition, and if the reference variable is converted to a parent class type, it is called upward transformation. There are various restrictions on the type conversion of a reference variable. And when you access static properties, static methods, instance properties, instance methods, and methods and properties inherited from the parent class by reference variables, the Java Virtual machine takes a different binding mechanism.
The 3.java compiler allows for type conversions between classes with direct or indirect inheritance relationships, and for upward transformation, you do not have to use coercion type conversions, because objects of subclasses can also be considered objects of the parent class. For example, a dog object is a animal object and an object
4. Using the parent class method to implement polymorphism
Parent class:
public class Animal {
public void Say () {
};
}
Sub-class:
public class Dog extends Animal {
public void Say () {
System.out.println ("dog");
}
}
Override the parent class method as long as the parent class method name is the same
Polymorphism in Java