jamesprogram.java
class jamesprogram {
public static void main(String args[]){
cat catObject = new cat();
catObject.simpleMessage();
}
}
In the above we create a new cat object called catObject. Once we have created a new object, we can access the methods of that class (simpleMessage()) in this example. The syntax before the = operator describes the ‘name of the class we are creating an object from and the declared name of this new object (cat catObject).
cat.java
// the public means anything can use it, it's 'public'
public class cat {
// public (anyone can use it)
// void (this method's going to do something but not
// return anything
public void simpleMessage(){
System.out.println("Another class");
}
}
Not suprisingly, this outputs the text
Another class