A reminder about the format of instance method calls.
--[Method name (argument)] for methods defined in the same instance --[Variable.method name (argument)] for the method defined in the instance --For static methods, [class name.method name (argument)]
Test.java
public class Test {
public void SayHello() {
System.out.println("Hello World");
}
public void Display() {
SayHello();
}
}
Create a new instance and use the reference that contains the variable (hello.SayHello ();).
Hello.java
public class Hello{
public void SayHello() {
System.out.println("Hello World");
}
}
Test.java
public class Test {
public static void main(final String[] args) {
Hello hello = new Hello();
hello.SayHello();
}
}
Use class name references (Hello.SayHello ();).
Hello.java
public class Hello{
public static void SayHello() {
System.out.println("Hello World");
}
}
Test.java
public class Test {
public static void main(final String[] args) {
Hello.SayHello();
}
}
The ones without parentheses are the access to the fields of the instance.
Thorough capture Java SE11 Silver problem collection
Recommended Posts