public class StaticInstanceDemo
{
public static void main ( ) {
String greeting = "Hello";
Stuff stuffObject = new Stuff ( ); // Creates an instance of the Stuff class
StaticInstanceDemo santa = new StaticInstanceDemo();
//^ tricky way for a static method to call an instance method
System.out.println ("outputing instance method stuffObject.doStuff ( )
yeilds...... " + stuffObject.doStuff ( ) );
System.out.println ("outputing stuffObject.data yields........................... "
+ stuffObject.data);
System.out.println ("outputing instance method stuffObject.doStuff (500)
yields... " + stuffObject.doStuff (500) );
blahBlah (greeting); // This method can be called within main because both
// blaBlah and main are static.
System.out.println ("calling static method Stuff.doStaticStuff ( ) yields.......... "
+ Stuff.doStaticStuff ( ) );
santa.hoHoHo ( ); // santa can call hoHoHo because the santa instance was
// created inside the main method.
}
// blahBlah is a static method of this class
public static void blahBlah (String s) {
System.out.println ("the blahBlah method says " + s);
}
// hoHoHo is an instance method of this class
public void hoHoHo ( ) {
System.out.println ("Santa says, \"Ho ho ho.\" ");
}
}