Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
medium

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

and Derived

B

Hello from Base and Derived

C

Compilation Error

D

Hello from Base

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

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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