Lab Quiz, Foundations of Computing, Spring, Week 6 -- Thurs May 10 2001

Name:


A file contains the following Java code (exactly as it appears here, there is nothing else in the file). The file is compiled by the Java compiler and the resulting Java program is run.

class Zeta {
    int i;
    public Zeta() { i = 0; }
    public void print_i() { System.out.print("  i " + i); }
}

class Sigma extends Zeta {
    int k; 
    public Sigma() { super(); k = 2; }
    public void print_k() { System.out.print("  k " + k); }
}

class Tau extends Sigma {
    int m;
    public Tau() { super(); m = 3; }
    public void print_m() { System.out.print("  m " + m); }
}

public class Inherit {
    public static void main(String argv[]) {
	Sigma s = new Sigma(); Tau t = new Tau();
	System.out.print("From s:"); s.print_i(); s.print_k(); 
	System.out.println();
	System.out.print("From t:"); t.print_i(); t.print_k(); t.print_m();
	System.out.println();
    }
}
  1. What is (are) the superclass(es) of Zeta?

  2. What is (are) the subclass(es) of Zeta?

  3. What is (are) the superclass(es) of Sigma?

  4. What is (are) the subclass(es) of Sigma?

  5. What is (are) the instance variables of Tau?

  6. What is (are) the instance methods of Tau?

  7. What class(es) do(es) the variable s belong to?

  8. What class(es) do(es) the variable t belong to?

  9. What output does the program produce?