Multiple Choice Section 13.1 Extended Classes
|
Throughout this section,
A is a class and B is
a new class that extends A.
Also, we have these variables:
A a = new A( );
B b= new B( );
B b1 = new B( );
B b2 = new B( );
|
-
What Java syntax is used to declare that a class B is extended from
class A?
- A. class A super B { ... };
- B. class B extends A { ... };
- C. class B from A { ... };
- D. class B : public A { ... };
-
If a class B is derived from A, then which
of the following terms describes A?
- A. ancestor class.
- B. base class.
- C. parent class.
- D. superclass.
- E. All of the above.
-
Using the variable declarations at the top of this section,
which of the following assignment statements are legal (no compilation errors)?
- A. a = b;
- B. b = a;
- C. b1 = b2;
- D. Both (A) and (B) are legal, but not (C).
- E. Both (A) and (C) are legal, but not (B).
- F. Both (B) and (C) are legal, but not (A).
-
Consider the assignment statement
a=b;
(with the variable
declarations at the top of this section).
Which answer is true?
- A. The assignment statement is illegal (compiler error).
- B. The assignment statement compiles okay, but sometimes causes a ClassCastException at runtime.
- C. The assignment statement compiles okay, and cannot cause a ClassCastException at runtime.
-
Consider the assignment statement
b=(B)a;
(with the variable
declarations at the top of this section).
Which answer is true?
- A. The assignment statement is illegal (compiler error).
- B. The assignment statement compiles okay, but sometimes causes a ClassCastException at runtime.
- C. The assignment statement compiles okay, and cannot cause a ClassCastException at runtime.
-
What is the term used to describe the situation when an extended
class provides a
function already provided in the superclass?
- A. Inheriting.
- B. Overriding.
-
Consider the declarations at the top of this section. Suppose there
are two methods: f has an argument of type A and g has an
argument of type B. Which statement is correct?
- A. Both f(b) and g(b) are legal activations.
- B. f(b) is legal, but g(b) is not legal.
- C. f(b) is not legal, but g(b) is legal.
- D. Neither f(b) nor g(b) is a legal activation.
-
Consider the declarations at the top of this section. Suppose there
are two functions: f has an argument of type A and g has an
argument of type B. Which statement is correct?
- A. Both f(a) and g(a) are legal activations.
- B. f(a) is legal, but g(a) is not legal.
- C. f(a) is not legal, but g(a) is legal.
- D. Neither f(a) nor g(a) is a legal activations.