Skip to content
CodeKruPro

Order of constructor calls with this() and super()

QuizMediumJava onlyAsked in: Accenture, Capgemini, Infosys, TCS, Wipro

What does new Kid(); print?

class Parent {
    Parent() { System.out.print("Parent "); }
    Parent(String s) { this(); System.out.print("Parent(" + s + ") "); }
}
class Kid extends Parent {
    Kid() { this("x"); System.out.print("Kid "); }
    Kid(String s) { super(s); System.out.print("Kid(" + s + ") "); }
}
  • Parent Parent(x) Kid(x) Kid
  • Kid Kid(x) Parent(x) Parent
  • Parent Kid
  • Parent(x) Parent Kid(x) Kid

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.

See Pro+

Already have Pro+? Sign in