Dachang interview questions, talk about the understanding of polymorphism?
1. The understanding of polymorphism: it can be understood as a variety of forms of a thing.
2. The manifestation of polymorphism in a broad sense:
①Method overloading and method rewriting
②Polymorphism of subclass objects
3. The manifestation of polymorphism in the narrow sense:
the polymorphism of subclass objects
4. What is subclass object polymorphism: the reference of the parent class points to the object of the subclass. (The object of the subclass is assigned to the reference of the parent class)
举例:前提:Student和Man都是Person类的子类
Person p = new Student();
Person p = new Man();
Object obj1 = new String("ABC");
Number n = new Integer(1);
5. Application of polymorphism:
virtual method call: when compiling, the called method is considered to be of the parent class, but when running, the actual execution is the method of the subclass overriding the parent class.
Note: the method call in polymorphism : Compile and look on the left, and run and look on the right!
6. Description of
polymorphism : polymorphism is only applicable to methods. Not applicable to attributes!