

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


public class Thing { private int count;
public Thing1( int count ) { this.count = count; }
public int getCount() { return this.count; }
public void setCount( int count ) { this.count = count; }
public String toString() { if ( this.count == 1 ) return "one"; else if ( this.count == 2 ) return "two"; else if ( this.count == 3 ) return "three"; else return "too many"; }
public static void swap1( Thing1 t1, Thing1 t2 ) { Thing1 temp;
temp = t1; t1 = t2; t2 = temp; } }
public class Question { public static void main( String[] args ) { Thing1 first = new Thing1( 4 ); Thing1 second = new Thing1( 2 );
System.out.println( first.toString() ); System.out.println( second.toString() );
Thing1.swap1( first, second );
System.out.println( first.toString() ); System.out.println( second.toString() );
Thing1 third = new Thing1( 1 ); Thing1 fourth = new Thing1( 3 );; second.setCount( third.getCount() ); first = fourth;
System.out.println( first.toString() ); System.out.println( second.toString() ); System.out.println( third.toString() ); System.out.println( fourth.toString() );
System.out.println( first.toString().equals( fourth.toString() ) ); System.out.println( second.toString().equals( third.toString() ) ); System.out.println( first == fourth ); System.out.println( second == third ); } }