Welcome Guest | Sign in | Register
Inner Classes - Discussion Page For Q.3024 | 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 {
SuperClass() {
}

static class SubClass {
SubClass() { }
}
}
Which is the correct way to declare the object of "Subclass" , which can be use outside the "Superclass" ?
A. SubClass Sub = new SuperClass().new SubClass(); B. SubClass Sub = new SuperClass.SubClass();
C. SuperClass.SubClass Sub = new SuperClass.SubClass(); D. SubClass SubClass Sub = new SuperClass.SubClass();

Answer and Explanation

Answer:SuperClass.SubClass Sub = new SuperClass.SubClass();

Explanation:
Because the inner class "Subclass" is declared 'static' that's why it is declared like this.

Comment on this Question

Name:

Loading...




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