1. Construction Method:
if the constructor method is not written in the class, the compiler adds a constructor method by default, with only one super () inside;
Class A {
Public A () {
Super ()
}
}
2. This is a special reference within the instance that holds the memory address of the current instance
facilitates the invocation of mutual calls between construction methods, often invoking the constructor of a parameter in a construction method with few parameters
This () must be the first line of code in the constructor method
Public A () {
This (0);
...
}
3. method overload overload. Different parameters with the same name. simplifies external interfaces.
Public String GetPrice (ID);
public string GetPrice (name)
4. Access control characters
|
This class |
Package |
Sub-class |
Other classes |
Public |
0 |
0 |
0 |
0 |
| Protected |
0 |
0 |
0 |
|
| [Default] |
0 |
0 |
|
|
| Private |
0 |
|
|
|
Use principle: use private as much as possible
Public is a contract with other developers, and the members of the community will remain stable.
5. Inheritance
Purpose: Code reuse, allowing only one parent class to be inherited
Inheritance: Members with access rights
do not inherit: Invisible Members, constructor methods, static members
To create a subclass instance execution order
1. Create the parent class instance first
2. Create subclass instances again
3, two sub-class instances are bound together as instances of subclasses
Construct Method Execution Order
1, first implement the parent class construction method
2, the sub-class construction method of re-execution
3.the default constructor method of the parent class super ()
If the parent class does not have an parameterless construction method, the parent class must be manually called to have the parameter constructor method in the child class.
6. Super:
1. The constructor of the parent class is called in the subclass: Super ()
2, but must be the first line of code to construct the method
3. When overriding a method, you can call the same method in the parent class.
4, Super.funcname ();
7. overriding Override
Purpose: The method that inherits from the parent class is rewritten in the subclass when it does not meet the needs of the child class.
Rules for overriding:
1. method signature ( return type, method name, parameter list ) must be consistent
2, the scope of access can not be smaller
3 and cannot throw more exceptions.
8. Polymorphism :
Role: Handle multiple seed type instances in a consistent type
1. Transition up: Subclass instance to parent class type
Shape s = new Line ();
2, upward transformation, the subclass of the unique members are wiped, can only invoke the parent class of common members.
3, downward transformation, must be forced to transform
4. Asubclass instance of the parent class type can be reverted to the original type
Line line = (line) s;
5. Operation Period Type identification
Instanceof, both the child type and the parent type return true.
9. Abstract class: Abstraction
1. Function:
1). provide generic code for subclasses
2). defines a generic for a subclass Api
2, semi-finished class, can not create an instance
3.classes that contain abstract methods must be abstract classes
4, abstract class does not have an abstract method (puzzled)
Final:
1, can be used to modify variables, methods, classes
2. The definition of constants is usually used together with final,static
3. Optimization of translation period or optimization of operation period
Final byte a = 2;
Final byte B = 3;
byte c= A + B;
compile time optimization to:byte c= 5;
4.Final Method: cannot be overridden by quilt class
5.final class: No sub-class, cannot be inherited
One. Static
1. Static Properties
2, belongs to the class, but does not belong to the instance
3. When called, the class name is usually used to call
4, can not use, try not to
5. Non-object-oriented syntax (basic data types also)
6. Shared Data Math.PI
7, tool method:math.sqrt ();
8. Static initialization block:
Static {
....
}
The first time the class is used, it is executed automatically and only this time.
Interface
1. function: Structural Design tool, used to decouple
2, the extreme abstract class
3, can only define
1), abstract method
2), constant
3), inner class, internal interface
4.all the members are public
5, can inherit multiple interfaces at the same time
6, the interface can inherit interface A extends B,c,d
Internal class
* classes defined within a class or in a local code block
* non-static inner class
*) belongs to the instance and is created with an external class instance
*) cannot define static members
Class A {
Class Inner {
}
}
A = new A ();
A.inner B = a.new Inner ();
A.inner B = new A (). New Inner ();
* static inner class
Class A {
Static Class Inner {
}
}
A.inner a = new A.inner ();
* local inner class
*) local inner class, using the outside local variables must be final
Class A {
void A (final int i) {
final int j=10;
Class Inner {
void A () {
I+j
}
}
Inner a = new Inner ();
}
}
* anonymous inner class
Super S = New super () {};
* Why use internal classes
*) based on personal design concept
*) Two types of relationships close
*) completely hidden type
This article is from a "sword Siege" blog, please make sure to keep this source http://weijiancheng.blog.51cto.com/10190955/1643961
Android_log_2_ Object-oriented excerpt