class TwoStringReferences  
{
  public static void main (String[] args) 
  {
    String strA;  // reference to the first object
    String strB;  // reference to the second object
    // create the first object and save its reference     
    strA = new String("first string"); 
    // print data referenced by the first object.
    System.out.println(strA);
    
    // create the second object and save its reference
    strB = new String("second string");
    // print data referenced by the first object.
    System.out.println(strA);
    // print data referenced by the second object.
    System.out.println(strB);   
  }
}
   
Back to Lesson 10 Examples
   
   Back to Java Main Page