java inheritance and polymorphism learning

Object-oriented three characteristics: encapsulation, inheritance, polymorphism.

Inheritance is a prerequisite for polymorphic, not if there is no inheritance polymorphism

The main problem is to solve the succession: the common extraction

Inheritance among the features: 1, subclasses can have the contents of the parent class 2, subclass can also have their own proprietary content.

Parent can also call the base class, superclass. Subclasses can also have their own proprietary content.

In the parent-child class inheritance, if the member variables of the same name, subclass object is created, accessed in two ways:

Access to member variables directly by subclass object: to the left of the equal sign is who, who on the first use, then there is no looking upward.

Indirect access by members of the member variables method: This method belongs to whom, on priority with who is not looking up.

Note: Regardless of the method or member variable is a member of, if not the father are looking up, never looking down subclass

Local variables: write directly to the member variable name

This class member variables:. This member variable name

The parent class member variables:. Super member variable name

In creating relationships among the parent class, create sub-class object, a member of the rules of access methods: Who created the object is, it is preferable with whom, if not then look up.

Rewriting (override): The concept: inheritance relationship among the same method name, parameter list, too.

Rewriting (override): the inheritance among the same method name, parameter list, too. Cover, override
overloaded (overload): the same method name, parameter list is not the same.

Methods overwritten features: create a subclass of the priority target sub-class method.

 

Guess you like

Origin www.cnblogs.com/zbb121/p/10926607.html