| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
medium Solved by 7 students
Inheritance and Method Call Errors
< Prev
Next >

Given the following class definitions:

public class SuperClass {
    // default constructor not shown ...
    public void methodX() {
        /* implementation of methodX */
    }
    public void methodY() {
        /* implementation of methodY */
    }
}

public class SubClass extends SuperClass {
    // default constructor not shown ...
    public void methodX() {
        /* different implementation from methodX in SuperClass */
    }
    public void methodZ() {
        /* implementation of methodZ */
    }
}

Assume that the following declarations are made in a client class:

SuperClass s1 = new SuperClass();
SuperClass s2 = new SubClass();
SubClass s3 = new SubClass();

Which of the following method calls will cause a compile-time error?

I. s1.methodZ();

II. s2.methodZ();

III. s3.methodY();

A

I and II only

B

I only

C

I, II, and III

D

II only

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2psak1211 3m 09s -89
#3y.seong202701 1m 44s -114
#4suhanakochhar00612 17m 28s -958
Items per page:
10
1 – 4 of 4

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy