Skip to content

Commit 87ccefd

Browse files
author
Ram swaroop
committed
added content
1 parent 6d68c6b commit 87ccefd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

_posts/2015-08-20-nested-classes.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,37 @@ D. Compilation fails due to multiple errors
608608
E. Compilation fails due only to an error on line 4
609609
F. Compilation fails due only to an error on line 7
610610

611+
__Q6.__
612+
613+
{% highlight java linenos %}
614+
class OuterClassAccess {
615+
private int size = 7;
616+
private static int length = 3;
617+
618+
public static void main(String[] args) {
619+
new OuterClassAccess().go();
620+
}
621+
622+
void go() {
623+
int size = 5;
624+
System.out.println(new Inner().adder());
625+
}
626+
627+
class Inner {
628+
int adder() {
629+
return size * length; // inner class can access static members of outer class
630+
}
631+
}
632+
}
633+
{% endhighlight %}
634+
635+
What is the result?
636+
637+
A. 15
638+
B. 21
639+
C. An exception is thrown at runtime
640+
D. Compilation fails due to multiple errors
641+
E. Compilation fails due only to an error on line 4
642+
F. Compilation fails due only to an error on line 5
643+
611644

0 commit comments

Comments
 (0)