Today we learned about Java classes and objects, and because the idea of Java object-oriented programming is almost the same as C + +, you need to focus more on some of the differences in Java.
1. Class
1.1 In the class of this piece, in addition to the basic member variables, member methods, constructors, and so on, need to master the difference between the three permissions modifiers, and will be reasonable to use (private restricted permissions in this class, protected limited permissions only within the package).
1.2 Static constants, variables, methods: static adornments. We can use the "class name. Static class member" to invoke, such as:
Public class statictest{ staticdouble pi=3.1415; Static int ID; Public void Test () { System.out.println (STATICTEST.PI); System.out.println (statictest.id); }}
It is also important to note that the This keyword cannot be used in static methods, and non-static methods cannot be called in static methods. However, you can call a static method in a non-static method.
Tip: When you want to perform initialization actions on a class, you can use static to define a static zone. Such as:
public class example{ static{ //some } }
1.3 Objects
In Java, everything can be considered an object, but a real action identifier is essentially a reference.
The reference to the object is simple, such as: Book Book;
Associate the reference with an object, such as:
Book Book=new book ();
In Java, the reference essentially holds the memory address of the object, is stored in the stack, and the object is stored in the heap. So the reference is not the object of storage, but generally we ignore the difference.
Also note: Comparison of objects, the difference between = = and the Equals method. The use of the Finalize () method for destroying objects.
Learning Notes--java Classes and objects