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 Solved by 1 students

Method Overriding With Super Keyword

Mark
< 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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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