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

Home > Java Programming > Inner Classes > Questions and Answers

Q: What is the output for the below code ?
class Outer {
static class Inner {
void go() {
System.out.println("Inner.go");
}
}
}
public class Test {
static class Inner1 {
void go() {
System.out.println("Inner1.go");
}
}
public static void main(String... args) throws Exception {
Outer.Inner bn = new Outer.Inner();
bn.go();
Inner1 in = new Inner1();
in.go();
}
}
A. Comile fail because Inner1 in = new Inner1(); Inner class can't be accessed without
having an instance of the outer class
B. Inner.go Inner1.go
C. Runtime Exception D. Runtime Exception

Answer and Explanation

Answer:Inner.go Inner1.go

Explanation:
Static Inner class can be accessed without having an instance of the outer class. This is like other static members.

Comment on this Question

Name:

Loading...




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