Different from C ++, Java is a pure object-oriented language. Object-oriented has three main features: inheritance, encapsulation, and polymorpism ).
This part contains a lot of content. 01 I will take an example to familiarize myself with the Java Class Object Construction Process. Here I need to remember one thing: In Java, the transfer of class objects is reference transfer.
Example:
Class person {// defines the property string name; int age of the class "person"; // defines the method void say () {system. out. println ("My name is:" + name + ", my age is:" + age) ;}} public class oodemo01 {public static void main (string ARGs []) {// declared object: declared in stack memory; Class Name object name = NULL; // instantiated object: Use new to open up space in heap memory and save object attributes; object Name = New Class Name (); person P = new person (); // pass through the object. attribute to set the property P. name = "James"; p. age = 23; // pass object. method: Call the Method P of the object. say ();}}
In this example, a person class is defined. To use a person class object in the main method, a person object must be declared and instantiated. The declared object is allocated in the stack memory. The instantiated object adopts the new class name () syntax to open up space in the heap memory. The objects allocated in the stack memory are referenced to operate the heap memory data.. This is very important and requires thorough understanding.
The above object construction process can be used to express the object reference transfer.