Phase 1 Language Basics + Advanced _1-3-Java language senior _02- inheritance and polymorphism _ Section 1 inherit inherit _3_ access features in a member variable

Create a parent class, which defines a member variable,


and then create sub-categories. Subclass extends the parent class

to create the parent object, there is only numFu this member variable


parent does not know where their child in class. Subclass aware of the existence of the parent class
subclass there are two members of the variable that contains the parent class and their


The same name

Member variable parent class and subclass What happens if the same name?

Num parent class definition 100 equal

sub-class also defines num, but equal to 200







indirectly
the parent class is defined inside MehtodFu output num

where num is present among the classes, subclasses will not find downwardly


subclass define methods, output NUM





methodFu is the parent class's methods, num is the output of the parent class.

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11209882.html