Java Review (3) Classes and Objects

See some recaps of the writing.

//Classes and objects // Object 
-oriented programming: encapsulation, inheritance, polymorphism Class members marked private can only be used in this class, not visible in subclasses, and not visible to classes in other packages. The class is marked, then all its data is hidden // public subclasses and classes of other packages can also use //protected marked class members only the subclasses or other classes in this package can access //not when declaring a class Using modifier permissions, the class is preset to the package access scope, that is, only a class in a package can call its class members //In addition to member methods, there are also constructors in the class (same name as the class, no return value) Used to create objects, whenever an object is instantiated, the class will automatically call the constructor // static data and static methods are usually used to provide shared data and methods, the this keyword cannot be used in static methods, and non-static methods cannot be called in static methods. Static method //When the life cycle of an object ends, it will be processed by the garbage collection mechanism that comes with the Java virtual machine //Get the properties and behavior of the object through "object.class members" //Comparison of objects, equals() compares the connection Whether the contents pointed to by the two objects are the same, "==" compares the memory address. Re-study //Destruction of objects: The situation that will be regarded as garbage is that the object exceeds the scope (ie {}) or assigns the object to NULL, and also understand finalized() and System.gc()










Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324406103&siteId=291194637