Welcome Guest | Sign in | Register
Inheritance - Discussion Page For Q.2838 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Inheritance > Questions and Answers

Q: What is the output for the below code ?

public class A {
public A(){
System.out.println("A");
}
public A(int i){
this();
System.out.println(i);
}
}
public class B extends A{
public B (){
System.out.println("B");
}
public B (int i){
this();
System.out.println(i+3);
}
}
public class Test{
public static void main (String[] args){
new B(5);
}
}
A. A B 8 B. A 5 B 8
C. A B 5 D. B 8 A 5

Answer and Explanation

Answer:A B 8

Explanation:
Constructor of class B call their superclass constructor of class A (public A()) , which
execute first, and that constructors can be overloaded. Then come to constructor of class B (public B (int i)).

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.