Classes/Objects  «Prev  Next»


Classes and Constructors - Quiz

Each question is worth one point. Select the best answer or answers for each question.
 
1. Which of the following are true?
Please select all the correct answers.
  A. If a class declaration does not have an extends clause, then the class is a direct subclass of Object.
  B. If a class is declared as abstract then it may not be declared as final.
  C. A top-level class (non-inner class) may be declared as private.
  D. A class may implement, at most, one interface.

2. Which describes the following class declaration?
class Circle extends Shape {
  Point center;
  double radius;
}

Please select the best answer.
  A. A circle has a shape that is a center point and a radius.
  B. A shape has a circle that is a center point and a radius.
  C. A circle is a shape that has a center point and a radius.
  D. A shape is a circle that has a center point and a radius.

3. Which of the following are true?
Please select all the correct answers.
  A. A constructor may be declared as private.
  B. The default constructor is inherited from a class's superclass.
  C. A constructor may throw an exception.
  D. A constructor has a void return value.

4. What is the output of the following program?
class SuperClass {
	int i, j;

	SuperClass(int i, int j) {
		this.i = i;
		this.j = j;
	}
	SuperClass() {
		this(2, 3);
	}
}

public class Question extends SuperClass {
	public Question() {
		System.out.println(i + j);
	}

	public static void main(String[] args) {
		new Question();
	}
}

Please select the best answer.
  A. 0
  B. 5
  C. 2
  D. A compilation error occurs.