We have illustrated a very simple application previously to display "Hello World!". Here is an
application that extends the previous Java application to include states and methods and to show how they
can be invoked from within the main()
method.
1 2 3 //An example class and application 4 5 import java.lang.*;6 7 public class TestClass extends Object
8 { 9 private int x, y=5;
10 11 public TestClass(int z)
12 { 13 x = z; 14 } 15 16 public void display() 17 { 18 System.out.println("The values of (x,y) are: (" + x + "," + y +")");
19 } 20 21 public static void main(String args[])
22 { 23 TestClass test = new TestClass(10);
24 test.display();
25 } 26 } 27 28
The full source code for this example is here -
TestClass.java
.
© 2006
Dr. Derek Molloy
(DCU).