This is about as simple as a Java program can be and still make some use of classes.
class Person
{
String name;
int age = 20;
void birthday ()
{
age++;
System.out.println (name + " is now "+ age);
}
}
public class People
{
public static void main (String args [])
{
Person john;
john = new Person ();
Person mary = new Person ();
john.name = "John Doe";
john.birthday ();
}
}
|
Compiling produces these two bytecode files:javac People.java
People.class
Person.class
java People
John Doe is now 21