Unit 9 AP Computer Science Practice Exam
Unit 9 AP Computer Science Practice Exam
Inheritance
1) Which of the following are true 4) Which of the following code inside
about the concept of inheritance? of the constructor of a subclass calls
the constructor of the superclass?
I. By extending a subclass from a
superclass, an “is-a” relationship (A) super();
is established. (B) init();
II. The super keyword is used to (C) constructor();
call the constructor of a subclass. (D) this();
III. The extends keyword is used
to establish an inheritance 5) In a subclass that extends a
relationship. superclass, how would a method be
called?
(A) I only
(B) I and II (A) super.this.method();
(C) I and III (B) super().method();
(D) II and III (C) method();
(E) I, II, and III No change, (D) extends.method();
method is already inherited
2) Classes that extend a superclass can 6) When a subclass has a method with
draw upon ______ from that the same signature (but different
superclass. body) than a method in its
superclass, the method is being:
(A) Fields only (A) Overdone
(B) Methods only (B) Overloaded
(C) Fields and methods only (C) Supered
(D) Fields, methods, and (D) Overridden
constructors
7) Given the following class header,
3) When writing a subclass, the only which is the superclass?
part required is the subclass’s ____
public A extends B
(A) Constructor
(B) Methods (E) A
(C) Fields (F) B
(D) Constructor and fields (G) Neither
(H) Both
public X extends Y
ArrayList<Y> myYList =
new ArrayList<Y>;
ArrayList<X> myXList =
new ArrayList<X>;
(A) myYList.add(xObj);
(B) myYList.add(yObj);
(C) myXList.add(xObj);
(D) myXList.add(yObj);
END OF SECTION I