This is used for a non-static class.
So first you need to create a class.
The main function is static so it doesn't do that automatically.
So create an object of Main type (or some other class from a file with the same name):
public class Main { public static void main(String[] args) { System.out.println("Hello World 1"); Main example = new Main("Hello World 2"); example.println(); } private String text; public Main(String text) { this.text = text; // copy the input argument to the class member } public void println() { System.out.println(this.text); // print the class member } } |