Java study notes -6- wrapper classes, static keyword, inheritance, polymorphism

Wrapper class

 

Integer.valueOf("55")

 

Converts a string to a corresponding type of packaging

Example:

Integer integer = Integer.valueOf("55");

 

Integer.parseInt()

Converts a string corresponding to the type of basic

Example:

 

int i = Integer.parseInt("10");

 

static keyword

Static method to access class variables and static methods directly.

 

Static methods can not directly access member variables or members of the general method.

On the other hand, members of the method can directly access the class variables or static methods.

 

Static method, you can not use this keyword.

 

Static methods can only access static members.

 

inherit

Java supports only single inheritance, do not support multiple inheritance

 

Java supports multi- level inheritance ( inheritance system )

 

Member variables

Member variable of the same name does not appear in the parent class subclass, you can directly access the parent class member variables

 

Use the same name super keyword, modifying the parent class member variables

super. parent class member variable name

 

Member method

Members of the method , the principle of proximity

 

Member method of the same name appears subclass the parent class, method overrides (Override)

 

Construction method

Name of the constructor method is consistent with the class name. So subclass can not inherit the parent class constructor.

 

The role of the constructor is to initialize the member variables. So subclass initialization process, you must first perform the initialization operation of the parent class. Constructor of a subclass of default have a Super () , it represents a call to the parent class constructor after the parent class member variables are initialized before they can be used to subclass.

 

super and this

At each subclass object is created, initialize the parent class space, and then create a subclass object itself. Subclass object that contains the object in the corresponding space of the parent class, can comprise a member of the parent class, if the non-members of the parent class private modified, the sub-class parent class members are free to use.

 

Polymorphism

Compile look left , run to see the right , others are looking to the left

 

Upcast

Parent class type  variable name = new subclass type ()

 

Downcast

Subclass type variable name = ( subclass type ) parent class variable name

 

Variable name instanceof reference data types ( classes , interfaces )

 

If the variable belonging to the data type, returns to true .

If the variable does not belong to the data type, returns to false .

 

Guess you like

Origin www.cnblogs.com/cmmplb/p/11735720.html