Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
public class Main { private String name; public void setName(String n) { name = n; } public String getName() { return name; } // main method will be called first when program is executed public static void main(String args[]) { /* * Syntax of java object creation is, <class-name> object-name = new * <class-constructor>; */ Main example = new Main(); // set name member of this object example.setName("Class"); System.out.println("Hello " + example.getName()); } } |
Output:
1 2 3 |
Hello Class |