| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
Share
About Exam
medium Solved by 2 students
Method Overriding With Super Keyword
< Prev
Next >

Consider the following class definitions. What is printed as a result of executing the main method in the Test class?

class Base {
    public String greet() {
        return "Hello from Base";
    }
}

class Derived extends Base {
    @Override
    public String greet() {
        return super.greet() + " and Derived";
    }
}

public class Test {
    public static void main(String[] args) {
        Derived d = new Derived();
        System.out.println(d.greet());
    }
}
A

Hello from Base

B

and Derived

C

Hello from Base and Derived

D

Compilation Error

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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