ProgrammingModerateInfosys DSE · Wipro Elite
What is printed?
What is printed?
class A {
A() { this(1); System.out.print("0"); }
A(int x) { System.out.print("1"); }
}
class B extends A { B() { super(); System.out.print("b"); } }
// main: new B();- A. 01b
- B. 10b
- C. 1b0
- D. b10
Correct answer: B. 10b
A() delegates to A(int) first (prints 1), then its own body prints 0, then B's body prints b.
More OOP with C++ and Java questions
- Which OOP principle bundles data with the methods that act on it and hides the internal state behind an interface?
- In Java, which keyword makes one class inherit from another class?
- What is the return type of a C++ constructor?
- Every Java class that declares no superclass implicitly extends:
- In C++, members of a class declared without any access specifier are:
- Which statement about Java String objects is correct?