Learning Java basic part notes

Three characteristics of object-oriented: encapsulation, inheritance, and polymorphism.
Class: an abstract concept. The result of the summary is abstracted out with common characteristics.
Object:
the process of creating an object by a real individual class is called "instancing", through the class new An object: A a=new A();
class=attribute+method
Define a class: modifier (can be omitted)+class+class name The
attribute is a variable (in the form of data); the method is a behavior
member variable (instance variable) Initial value, no local variables (int 0; float 0.0f, double 0.0; char\u000; reference data type null; Long 0.0l)
Data types: basic data types and reference data types (all classes are reference data types)
new Open up a space in the heap memory, local variables and methods in the stack, push the stack (method call), pop the stack
. The difference between references and objects: Objects are new in the heap; references are a variable
reference that stores the object memory.
The prerequisite for the occurrence of a null pointer exception for local variables is: null reference to access related data.
Construction method: creation of objects and initialization of instance variables.
Syntax structure: modifier + construction method name (formal parameter list) {construction method body}
construction method name and The class name must be consistent, no need to specify the return type (cannot write void). The
constructor supports method overloading.
When the constructor is manually written in a class, the system will no longer provide parameterless construction
encapsulation: private modification, attribute privatization, only Access in this class,
get method: public return value type + get attribute name (no parameters) {return};
set method: public void set+property name (including parameters) {a=parameter}
contains static method, call: class name + method name; method
without static is called instance method, new object then access
static keyword: use static Modification is at the class level, using class name access.
Static variables are initialized when the class is loaded. Don’t use new objects. There are method areas.
Local variables: stack; instance variables: heap; static variables: method area
instances must be accessed by instance, static use The reference point is also a static static code block. The class load is generated and can only be loaded once. The static code block
is executed before the main() method. This is a reference, a variable, an object and a this. The current object can only be used in instance methods. Use
this (instance parameter) to call another construction method, appear in the first line of the construction method, do not appear twice.
Inheritance extend: subclass inherits the parent class, single inheritance
override override: the two classes have inheritance relationship ; Method name, return value type, and formal parameters are the same; access permissions cannot be lowered, the rewritten method cannot throw more exceptions than the previous method, fewer
private methods cannot be overwritten (overridden), and the constructor cannot be Inheritance cannot be overridden. Method overriding is only for instance. Method overloading in a class. Method overriding in a class with inheritance relationship.
Upcasting: The reference of the parent type points to the sub-type object, the parent class f=new subclass ()
Polymorphism: Compilation, different running states (bind the parent class method at the compilation stage, and dynamically bind the child class object method at the runtime stage) instanceof: the result of the operation is true false (reference instanceof type) Example: a instanceof B a is a reference to B as
The role of true polymorphism: reduce the coupling degree of the program, improve the expansion force

Guess you like

Origin blog.csdn.net/weixin_45328923/article/details/113121500