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

Home > Java Programming > Inner Classes > Questions and Answers

Q: Given below the sample code :
class SuperClass {
public static void main(String[] args) {
new SubClass();
}

SuperClass() {
System.out.print("Inside SuperClass ");
}
}

class SubClass extends SuperClass {
SubClass() {
System.out.print("Inside SubClass");
}
}
What is the output of the following code ?
A. Inside SuperClass  B. Inside SubClass
C.  It will give compile error D. Inside SuperClass Inside SubClass.

Answer and Explanation

Answer:Inside SuperClass Inside SubClass.

Explanation:
Because the 'SuperClass' constructor automatically run, therefore the first output would be "Inside SuperClass" & after it, the instance of the "SubClass" is called which in turn prints "Inside SubClass".

Comment on this Question

Name:

Loading...




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