java learning day13

Polymorphism
Upcast
People p=new Student();
When the reference of the parent class points to the object of the child class, only the methods already owned in the parent class can be used, and the unique methods in the child class cannot be used
When in the parent class When a method is used, first check whether the method is overridden. If it is not overridden, then call and
execute the method in the parent class. If it is overridden, then call the method in the subclass.
Look at the reference when compiling, and when executing Look at
the object
Downcast Student s=(Student)p
is similar to the coercion of variables.
Abstract
abstract class is decorated with the modifier abstract.
Features : Cannot create objects
. The meaning of abstract classes is to be used for inheritance.
How to obtain objects of abstract classes?
Parent class references point to subclass objects Differences between
abstract classes and ordinary classes
Ordinary classes: member variables, constructors, member methods
Abstract classes:
1. You can define variables and constants (same as non-ordinary classes)
2. There are constructors, However, objects cannot be created, in order for subclasses to access the data initialization of the parent class
3. There can be abstract methods or non-abstract methods. Classes


with abstract methods must be abstract classes.
Abstract classes do not necessarily have abstract methods.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325824451&siteId=291194637