Home > Java > javaTutorial > body text

How to use new instantiation in java

PHPz
Release: 2023-05-16 19:04:04
forward
1688 people have browsed it

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 class

will 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. Instance

Use 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();
}
 
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!