

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 While { public static void main( String[] args ) { final int MAX = 5; int i = 3, j = -1;
while ( i < MAX ) { j = i; while ( j <= MAX ) { --j; System.out.println( i + " " + j ); j += 2; } i++; }
System.out.println( i + " " + j ); } }
public class Trace { public static void main( String[] args ) { foo2(); System.out.println( "main1" ); foo3(); System.out.println( "main2" ); foo1(); System.out.println( "main3" ); }
public static void foo1() { System.out.println( "A" ); }
public static void foo2() { System.out.println( "B" ); foo1(); }
public static void foo3() { foo2(); System.out.println( "C" ); } }
Thing1 thing1; Thing2 thing2; Speakable speakable;
public interface Speakable { public abstract void speak(); }
class Thing1 implements Speakable { private static final String SPEAK = "Me";
public Thing1() { // ctor initialization here }
public String speak() { return SPEAK; }
public void doit( String s ) { // Thing1 does its thing with s } }
class Thing2 implements Speakable { public static final String SPEAK = "No, Me";
public Thing2() { // ctor initialization here }
public String speak() { return SPEAK; }
public void doit() { // Thing2 does its thing } }
thing1 = new Thing1(); _______
thing1.speak(); _______
thing1.doit(); _______
thing1.doit( "Yours" ); _______
String s1 = Thing1.SPEAK; _______
thing2 = new Thing2(); _______
thing2.doit( "Theirs" ); _______
thing2.speak(); _______
thing2.doit(); _______
String s2 = Thing2.SPEAK; _______
speakable = new Speakable();_______
thing1 = thing2; _______
thing1 = speakable; _______
speakable = new Thing1(); _______
speakable.speak(); _______
speakable.doit( "Mine" ); _______
speakable = thing2; _______
speakable.speak(); _______
speakable.doit(); _______