Welcome Guest | Sign in | Register
Inner Classes - Discussion Page For Q.3034 | 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 {
private String x = "Outer variable";
void doStuff() {
String z = "local variable";
class Inner {
public void seeOuter() {
System.out.println("Outer x is " + x);
System.out.println("Local variable z is " + z);
}
}
}
}
A. Compile Fail : local variable z is can't access from within inner class B. Compilation succeed but Runtime Exception
C. Compile without error. D. None of the above

Answer and Explanation

Answer:Compile Fail : local variable z is can't access from within inner class

Explanation:
the inner class object cannot use the local variables of the method the inner class is in.
only final can be accessible.

Comment on this Question

Name:

Loading...




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