super.method() and this(...) together
Predict the outputMediumJava onlyAsked in: Capgemini
class Parent {
Parent() {
System.out.println("Parent()");
}
void greet() {
System.out.println("hello from Parent");
}
}
class Child extends Parent {
Child() {
this("guest");
System.out.println("Child()");
}
Child(String name) {
System.out.println("Child(" + name + ")");
}
@Override
void greet() {
super.greet();
System.out.println("hello from Child");
}
}
public class Main {
public static void main(String[] args) {
new Child().greet();
}
}
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.