Object: Everything that exists objectively is an object
Syntax section:
Concept of Class: 1. Class is an abstraction of an object
2. Class is the subjective response of objective things in the human brain
3. Class is a template for objects
Design of the class:
Properties: Define location: Within class, Outside method
Instance variable: 1 has a default value,
2 is valid at least within this class,
3 can be repeated with local variables named, local variables first
Method: Function Remove static
Declaration part: Modifier return value type method name parameter table exception
Implementing the Partial {} method
Construction Method: Special method
A. The construction method must be the same as the class name
B. No return value type component, modifier method Name parameter table exception
C. Calling a constructor method when creating an object that cannot be called manually
Function: A method of constructing a parameter, assigning a value to a property
Note: If you do not write any construction methods, the default is to expose the non-parametric construction method
If you are writing a constructor with parameters, the system is no longer the default method of constructing
To create an object:
Syntax: New construction Method (construction parameter);
Student student1 = new Student ();//call to construct without parameters
Student Student2 = new Student (1, "yy");//Call the constructor method with parameters
This keyword:
A. The syntax is more rigorous,
The constructor method of this class, which must be in the first sentence of the constructor method.
Note: Do not recursively call construction methods
B. Inside the class, add this when invoking the instance variable
Local variables take precedence when local variables and instance variables are named repeatedly.
If you want to use an instance variable plus this. Property name
Overloading of methods (overload)
Role: Shielding the user's use of the differences, call the method more flexible
Syntax requirements:
1. Method names are the same
2. The parameter list is different (different type, number, order);
3. Return value does not require
Three main features of object-oriented:
1. Encapsulation
Code implementation: Private to the property, providing a public Set/get method
2. Inheritance
Keyword: extends
Such as: A extends B---> B is the parent class of a
① private methods can not inherit
② constructor method can not inherit
Keyword: super
①super. Property name, method name means the property that accesses the parent class, or the method that calls the parent class
②super (), an incoming argument refers to the constructor of the calling parent class, which must be placed in the first row of the constructor method
In the construction method, if there is no this and no super, then the system will add a default
Override of Method: A subclass inherits the parent class in a method that has a special implementation
Syntax requirements: 1, function name must be the same, parameter table, return value type same (declaration)
2, modifier: the same or wider than the parent class
The access permission for the modifier is from narrow to wide:
Private----> Default--->protected--->public
From general to special relationship: The parent class is the abstract of the subclass commonality
Instanceof represents a subordinate relationship, is ... of a
3. polymorphic
① a reference to the parent class to the object of the child class
Animal a = new Dog ();
② compile-time polymorphism: A reference can only invoke a method under its reference or access a property under a reference
③ run-time polymorphism: When running, the overridden method is called based on the actual type
The nature of polymorphism: overloading of methods and coverage of methods
① used on the return value
Public A M () {} The return value is a class or its subclasses
Polymorphic use in the parameter table
Public return value type M (a a) {} parameter table can be Class A or subclass a
Java object-oriented knowledge points