a java object-oriented

First package

Benefits of encapsulation:
1. To improve the security of data
2. The transmission of data to facilitate
the step of encapsulation:
1. Set property privatization
2. The private property of each getter and setter
3. In the get and set methods for properties operating restrictions

The second method of construction and method overload

Any class has a default constructor, the default constructor is no argument
when in a class manually define a constructor after the default constructor automatically disappear
constructor:
constructor method and class names must match
None return type constructor
uses:
1. Create an object
2. the object initialization operation performed

Method overloading:
1. In a class, are formed between the plurality of reload method
2. Method overloading rules:
2.1 must be the same method name
parameter list 2.2 methods must be different (different types, different number and different sequence)
Method weight benefits uploaded:
method name multiplexing

Third inheritance

1. subclass inherits the parent class, subclass automatically have non-proprietary properties and methods of the parent class
2.super keyword is a reference to the parent object, in subclasses
3.super (name, school) indicates that the call a parent class constructor
4.this () represents a call to the current constructor class
5. You must create the parent object when you create a subclass of object, and do not need to create new keyword parent object
6. in the subclass constructor must first call the parent class constructor, if the constructor subclass
constructor method, subclasses of the parent class constructor does not automatically call the constructor method call parent class parameters without
7. method rewritten:
the child-parent between classes, subclasses a method overrides a superclass method is
declared as part of the method (access can be different, but access rights less than subclasses not the parent class)
8. parent class declaration, the actual incoming objects are subclasses of the object, this is called polymorphism
in the multi-state, it is possible to call the parent class method is a method declared
subclass execution time and execution has been rewritten
9. Inheritance advantages:
code reuse
Let clearer structure between classes

Guess you like

Origin www.cnblogs.com/quanmeng/p/12179866.html