← Quiz: OOP Interview Questions: all 10 questions
Quiz: OOP Interview Questions · Question 7 of 10
What does this print? (code)
What does this print?
class Parent {
static String kind() { return "parent"; }
}
class Child extends Parent {
static String kind() { return "child"; }
}
public class Main {
public static void main(String[] args) {
Parent p = new Child();
System.out.println(p.kind() + " " + Child.kind());
}
}
- A.child child
- B.parent parent
- C.parent child
- D.Compile error
Answer & explanation
Correct answer: parent child
Static methods are hidden, not overridden: p's declared type Parent decides the first call.
Can you get the rest right without peeking?
Take the timed Quiz: OOP Interview Questions quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →