These are the questions for Lab Assignment Ten: 

---------------------------------------------------------------------------------

1. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta();
  }
  Alpha(int i) {  }
}

class Beta extends Alpha { }

Here are some possibilities: 

(a) The code does not compile because Beta does not define a no-args constructor. 
(b) The code does not compile because Beta does not define any constructors whatsoever. 
(c) The code compiles and runs succesfully, with no output. 
(d) The code does not compile because Alpha doesn't define a no-args constructor. 
(e) None of the above.

Don't forget: first write the answer down on paper. Then type the code in the 
computer and check. Finally indicate what the result was and what that means for 
your understanding.

---------------------------------------------------------------------------------

2. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta(3);
  }
  Alpha (int i) {  }
}

class Beta extends Alpha {
  Beta(int i) {
  }
}

Here are some possibilities: 

 (a) The code does not compile because Beta's constructor is empty. 
 (b) The code does not compile because Alpha doesn't define a no-args constructor. 
 (c) The code compiles and runs succesfully. 
 (d) The code does not compile because Beta does not define a no-args constructor. 
 (e) None of the above.

---------------------------------------------------------------------------------

3. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta(3);
  }
  Alpha() { System.out.println(0); }
  Alpha(int i) {
    System.out.println(i);
  }
}

class Beta extends Alpha {
  Beta()      { }
  Beta(int i) { }
}

Here are some possibilities: 

 (a) The code does not compile because Beta's constructors are empty. 
 (b) The code compiles and runs succesfully, but there is no output. 
 (c) The code compiles and runs succesfully, and outputs 0. 
 (d) The code compiles and runs succesfully, and outputs 3. 
 (e) None of the above.

---------------------------------------------------------------------------------

4. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta(3);
  }
  Alpha() {
    System.out.println(0);
  }
  Alpha(int i) {
    System.out.println(i);
  }
}

class Beta extends Alpha {
  Beta() {
    super(6);
  }
  Beta(int i) {
    this();
  }
}

Here are some possibilities: 

 (a) The code compiles and runs succesfully, and outputs 0. 
 (b) The code compiles and runs succesfully, and outputs 3. 
 (c) The code compiles and runs succesfully, and outputs 6. 
 (d) The code does not compile because at least one of Beta's constructors is not defined legally. 
 (e) None of the above.

---------------------------------------------------------------------------------

5. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta(3);
  }
  Alpha() {
    System.out.println(0);
  }
  Alpha(int i) {
    System.out.println(i);
  }
}

class Beta extends Alpha {
  Beta() {
    super(6);
  }
  Beta(int i) {
    super(3);
    this();
  }
}

Here are some possibilities: 

 (a) The code compiles and runs succesfully, and outputs 0. 
 (b) The code compiles and runs succesfully, and outputs 3. 
 (c) The code compiles and runs succesfully, and outputs 6. 
 (d) The code does not compile because at least one of Beta's constructors is not defined legally. 
 (e) None of the above.

---------------------------------------------------------------------------------

6. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta(12);
  }
  Alpha() {
    System.out.print(0);
  }
  Alpha(int i) {
    System.out.print(i);
  }
}

class Beta extends Alpha {
  Beta() {
  }
  Beta(int i) {
    this();
    System.out.print(3);
  }
}

Write your answer here: __________ (and explain). 

---------------------------------------------------------------------------------

7. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Alpha f = new Beta();
    System.out.println(f.test(3));
  }
  String test(int i) {
    return (i + 2) + " ";
  }
}

class Beta extends Alpha {
  String test(int i) {
    return (i + 1) + " ";
  }
  String test(long i) {
    return i + " ";
  }
}

Here are some possibilities: 

 (a) The code compiles and runs succesfully, and outputs 3. 
 (b) The code compiles and runs succesfully, and outputs 4. 
 (c) The code compiles and runs succesfully, and outputs 5. 
 (d) The code does not compile. 
 (e) None of the above.

---------------------------------------------------------------------------------

8. What is the result of attempting to compile and run this code?

class Alpha {
  public static void main(String[] args) {
    Beta f = new Alpha();
    System.out.println(f.test(3));
  }
  String test(int i) {
    return (i + 2) + " ";
  }
}

class Beta extends Alpha {
  String test(int i) {
    return (i + 1) + " ";
  }
}

Here are some possibilities: 

 (a) The code compiles and runs succesfully, and outputs 3. 
 (b) The code compiles and runs succesfully, and outputs 4. 
 (c) The code compiles and runs succesfully, and outputs 5. 
 (d) The code does not compile. 
 (e) None of the above.

---------------------------------------------------------------------------------

9. What is the result of attempting to compile and run this code?

abstract class Alpha {
  int value;
  Alpha (int value) {
    this.value = value;
    System.out.println(value);
  }
  public static void main(String[] args) {
    Beta f = new Beta(1999);
  }
}

class Beta extends Alpha {
  Beta  (int value) { super(value); }
}

Here are some possibilities: 

 (a) The code will compile and 1999 will appear in the standard output. 
 (b) The code will compile but nothing will appear in the standard output. 
 (c) The code will not compile because Alpha is abstract. 
 (d) The code will not compile because there is no default, no-args constructor for Alpha. 
 (e) None of the above.

---------------------------------------------------------------------------------

10. Consider the following program:

abstract class Alpha {
  abstract void complain();
}

class Beta extends Alpha {
  void complain(String s) {
    System.out.println(s);
  }
}

class Tester {
  public static void main(String[] args) {
    Beta f = new Beta();
    f.complain("There's a tomato in every automaton.");
  }
}

What will happen if you try to compile and execute the Tester class?

Here are some possibilities: 

 (a) The program will compile and run. 
 (b) The code will not compile because Beta has no default no-arg constructor. 
 (c) The code does not compile because Beta is abstract. 
 (d) The code does not compile because Tester does not inherit from Alpha. 
 (e) None of the above.

--