1. The concept
is "Create a Java object" ----- allocate memory and return a reference to the memory.
2. Notes
(1) The Java keyword new is an operator. Operators such as , -, *, / have the same or similar precedence .
(2) Creating a Java object requires three steps: declaring reference variables, instantiating, and initializing object instances.
(3) Before implementation, the parameterless constructor of the parent classwill be called by default, that is, the object of the parent class will be created
3 .Two instantiation methods(1) Object name = new class name (parameter 1, parameter 2...parameter n);
Object name.Method();
(2) new class name (parameter 1, parameter 2...parameter n). Method;
4. InstanceUse a Simple code to illustrate the two ways of instantiating an object:
package New; public class wordTest { public void wordtime() { System.out.println("工作日为:周一到周五"); } public static void main(String[] args) { wordTest wt=new wordTest(); wt.wordtime(); } }
The above is the detailed content of How to use new instantiation in java. For more information, please follow other related articles on the PHP Chinese website!