More Advanced Version of Hello World in Java.
public class HelloWorld
{
// instance variable
private String textToPrint;
/**
* main method
*/
public static void main(String [] args)
{
// create a HelloWorld object
HelloWorld myObject = new HelloWorld("Hello, world!");
myObject.printText();
}
/**
* Constructor for objects of class HelloWorld
*/
public HelloWorld(String text)
{
// initialise instance variables
textToPrint = text;
}
/**
* The printText method prints text stored in the
* object to the screen.
*/
public void printText()
{
// print the text to the screen
System.out.println(textToPrint);
}
}