| 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
Accessing Superclass Instance Variables
< Prev
Next >

Consider the following class definitions. What is printed when the main method is executed?

public class FirstClass {
    int x = 1;
}

class SecClass extends FirstClass {
    int x = 15;
    
    void printNum() {
        System.out.println("x is " + x);
        System.out.println("x is also " + super.x);
    }
    
    public static void main(String[] args) {
        new SecClass().printNum();
    }
}
A

x is 1
x is also 1

B

x is 15
x is also 15

C

x is 1
x is also 15

D

x is 15
x is also 1

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki12 0m 00s 90
#2gtsak3111 0m 54s 46
#3psak1211 1m 48s -8
#4suhanakochhar00611 7m 11s -331
Items per page:
10
1 – 4 of 4
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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