IU Bloomington Evaluation Services and Testing

Indiana University
Bloomington Evaluation Services and Testing

QuizSite  Students
Quizzes · Tests · Evaluations · Surveys
Activity: Practice_Ten
Student: dgerman (Adrian German)
Instructor: dgerman
Course: J201 Section: 4285
This is a copy, a snapshot. Don't submit from this page.

Please go to QuizSite and submit there (dgerman-C212)

Thank you.

Question 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 { }

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


Question 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) {
  }
}

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


Question 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) { }
}

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


Question 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();
  }
}

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


Question 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();
  }
}

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


Question 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:


Question 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 + " ";
  }
}

The code compiles and runs succesfully, and outputs 3.
The code compiles and runs succesfully, and outputs 4.
The code compiles and runs succesfully, and outputs 5.
The code does not compile.
None of the above.


Question 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) + " ";
  }
}

The code compiles and runs succesfully, and outputs 3.
The code compiles and runs succesfully, and outputs 4.
The code compiles and runs succesfully, and outputs 5.
The code does not compile.
None of the above.


Question 9.
What is the result of attempting to compile and run this code?
class Alpha {
  public static void main(String[] args) {
    Alpha 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) + " ";
  }
}

The code compiles and runs succesfully, and outputs 3.
The code compiles and runs succesfully, and outputs 4.
The code compiles and runs succesfully, and outputs 5.
The code does not compile.
None of the above.


Question 10.
What is the result of attempting to compile and run this code?
class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta();
    System.out.println(test(3));
  }
  String test(int i) {
    return (i + 2) + " ";
  }
}
class Beta extends Alpha {
  String test(int i) {
    return (i + 1) + " ";
  }
}

The code compiles and runs succesfully, and outputs 3.
The code compiles and runs succesfully, and outputs 4.
The code compiles and runs succesfully, and outputs 5.
The code does not compile.
None of the above.


Question 11.
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); }
}

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


Question 12.
What is the result of attempting to compile and run this code?
class Alpha {
  public static void main(String[] args) {
    System.out.println("... won't compile");
  }
  public static void main() {
    System.out.println("... will not run");
  }
}

The program does not compile because main is not defined correctly.
The program compiles but when you try to run it complains about main.
The program compiles and runs and prints ... won't compile
The program compiles and runs and prints ... will not run
None of the above.


Question 13.
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?

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


Question 14.
Consider the following code:
class Alpha {
  String message;
  Alpha (String msg) { message = msg; }
}
class Beta extends Alpha {
  Beta (String msg)  { message = msg; }
}
class Tester {
  public static void main(String[] args) {
    Beta f = new Beta("Greetings");
    System.out.println(f.message);
  }
}
You place the entire code in a file, called TwentyThree.java, and then try to compile and run it. What happens?

The code compiles and runs fine with no output
The code compiles, runs and outputs Greetings
The compiles but doesn't run
The code does not compile


Click to submit your answers.   Help


This activity is available between these dates and times: 07.20.10:00-08.06.23:59
It can be submitted a total of 30 times.
If it is a scored activity, the highest non-zero score will be counted.


Screen: TAKE_QUIZ
Last updated: Thu Mar 8 13:40:07 2001
URL: https://www.indiana.edu/~best/cgi-bin/quizsite/students.pl
Comments: best@indiana.edu
Copyright 2000, BEST & The Trustees of Indiana University