interface PersonInterface { public int getId() ; } class Person implements PersonInterface { int id ; String firstName ; String laststName ; //a static data member does not need //an instance of an object. It is not //associated with an object. static int NoPersonObjects = 0 ; //Constructor called when creating the object Person() { NoPersonObjects++ ; } public int getId() { return id ; } //A static method is like a global method static int getNoPersonObjects() { //Cannot access class data members //id firstName return NoPersonObjects ; } } public class Reference { public static void incrementPersonId( Person personObject ) { //Any changes made here are made in the object in the heap //and are reflected in the original object personObject.id++ ; } public static void main( String args[] ) { //Compiler will not allow //Person personObject ; //null means there does not exist a value //yet for the personObject1 Person personObject1 = null ; System.out.println( personObject1 ) ; // Can't call a method without an object // getId() //We get a handle/reference but it's not the //raw memory address to the person object. //Person object is created on the heap personObject1 = new Person() ; personObject1.id = 1 ; System.out.println( "personObject.getId(): " + personObject1.getId() ) ; Person personObject2 = new Person() ; personObject2.id = 2 ; incrementPersonId( personObject2 ) ; System.out.println( "personObject2.id: " + personObject2.id ) ; //Using the static method getNoPersonObjects() System.out.println( "static method Person.getNoPersonObjects():" + Person.getNoPersonObjects() ) ; System.out.println( "static method personObject1.getNoPersonObjects():" + personObject1.getNoPersonObjects() ) ; //Using the static data member NoPersonObjects System.out.println( "static data member Person.NoPersonObjects:" + Person.NoPersonObjects ) ; System.out.println( "static data member personObject1.NoPersonObjects:" + personObject1.NoPersonObjects ) ; PersonInterface personInterfaceObject = personObject2 ; //Compiler error no access to id //System.out.println( personInterfaceObject.id ) ; //Can call methods defined in the interface System.out.println( personInterfaceObject.getId() ) ; } }