#113 Method Overriding and a super Call
What will be printed and why?
public class Main {
public static void main(String[] args) throws Exception {
First first = new Second();
first.useTest();
Second second = new Second();
second.useTest();
second.callTest();
}
}
class First {
protected void test() {
System.out.println("First");
}
public void useTest() {
test();
}
}
class Second extends First {
@Override
protected void test() {
System.out.println("Second");
}
public void callTest() {
super.test();
}
}Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor