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

Home > Java Programming > Inheritance > Questions and Answers

Q: class A{
A(int i){
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[]){
A a=new A(10);
B b1=new B(20);
} }
A. 1,2,20 B. 20,2,1
C. compile time error D. run time error

Answer and Explanation

Answer:compile time error

Explanation:
in main() method we are creating an object of class A as well as class B by calling A and B class constructor, class B constructor will call super class constructor because in each constructor body super() keyword will be there by default with no parameter ,but in class A there is no constructor with no parameter ,so it will throw an compile time error.

Comment on this Question

Name:

Loading...




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