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

Home > Java Programming > Inheritance > Questions and Answers

Q: class A{
int I;
A(){
System.out.println(1);
} }

Class B extends A{
B(int i){
System.out.println(2);
This.i=I;
}}

Class Manager{
Public static void main(String args[]){
B b1=new B(20);
System.out.println(b1.i);} }
A. 1,2,20 B. 20,2,1
C. compile time error D. run time error

Answer and Explanation

Answer:1,2,20

Explanation:
in main() method we are creating an object of class B by calling B class constructor, class B constructor will call super class constructor because in each constructor body super() keyword will be there by default, so first class A constructor will execute then class B constructor finally main() method. So ans a)is correct

Comment on this Question

Name:

Loading...




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