codegym-Java syntax

1. In the class method, the instance method/member variable method name/variable name is statically modified, and the default prefix is ​​the class name; if there is no static modification, the default prefix is ​​this.

2. Construction method: The construction method is a method specifically used to create an object. When we create an object through the keyword new, we actually call the construction method.

public 类名称(参数类型 参数名称){
    
    
	方法体
}

The name of the constructor must be exactly the same as the name of the class it is in, even the case must be the same.
Don't write the return value type in the constructor, and don't even write void.
The constructor cannot return a specific return value.
If no construction method is written, the compiler will give a construction method by default, without parameters, the method body will not do anything.
Once at least one constructor has been written, the compiler will no longer give it away.

public class Test {
    
    	
	public void Test() {
    
    
		System.out.println("普通方法");
	}
	public Test() {
    
    
		System.out.println("无参的构造方法");
	}
	public static void main(String[] args) {
    
    
		Test test = new Test();
		test.Test();
	}
}

3. Thread.sleep() is a static method of the Thread class, which causes the current thread to sleep and enter the blocked state (suspend execution). If the thread is interrupted in the sleep state, an IterruptedException will be thrown.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41536271/article/details/115270041