What are classes and objects
How to define a class in Java
How to use objects in Java
member variables and local variables in Java
1. Member variables: defined in a class that describes the components that make up the object.
2, local variables: In the method of the class, to temporarily save the data.
3. Valid range of member variables: All methods in a class can call member variables.
4, local variables and member variables allow duplicate names, this time local variables have a higher priority.
How to construct in Java
1, if you do not write their own method of construction, Java will default to a non-parametric construction method. However, if the constructor is customized, the parameterless constructor given by the system will fail, regardless of the parameters.
2. When writing the constructor, you can check the rationality of the parameters by the way.
3, previously saw a description of the constructor: the constructor is the new moment of execution code, not necessarily used to initialize the object.
Static variables used in Java
1. Static variables are class-owned and shared by all objects of the class.
2, can be accessed with objects, but it is strongly recommended to use the class name Access .
Static methods for using static in Java
1, static methods can be directly called in the same class of static members (methods), but not directly call non-static members (methods).
2. If you want to invoke a non-static variable (method) in a static method, you can access the non-static variable (method) by creating the object of the class and then through the object. For example: in the main () method.
3, in the ordinary member method, you can directly access the same kind of non-static variables and static variables.
Static initialization block used in Java
1, static initialization block only executes when the class is loaded and executes only once (and is executed first), while static initialization blocks can only assign values to static variables and cannot initialize normal member variables.
2. Instead of static initialization blocks are executed once each time new.
3. initialization blocks always take precedence over constructors .
Introduction to the second season of Java first chapter classes and objects