Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 615cf3f

Browse files
Add files via upload
1 parent c46b2c8 commit 615cf3f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎NestedClass/NestedClass4.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package NestedClass;
2+
3+
class OuterClass {
4+
// static
5+
static int x_static;
6+
// nonstatic
7+
int x_nons;
8+
// private static
9+
private static int x;
10+
11+
private int x_pri;
12+
13+
OuterClass(int a, int b, int c, int d) {
14+
x_static = a;
15+
x_nons = b;
16+
x = c;
17+
x_pri = d;
18+
}
19+
void show(){
20+
if (x_nons>20) {
21+
class Inner {
22+
23+
void display() {
24+
System.out.println("static int" + x_static);
25+
System.out.println("Private static int" + x);
26+
System.out.println("Nonstatic Integer" + x_nons);// cannot be accessed directly
27+
System.out.println("Nonstatic Private integer" + x_pri);// cannot be accessed directly
28+
}
29+
}
30+
Inner obj = new Inner();
31+
obj.display();
32+
}
33+
else{
34+
System.out.println("No inner class");
35+
}
36+
}
37+
}
38+
39+
/**
40+
* NestedClass3
41+
*/
42+
class NestedClass4 {
43+
44+
public static void main(String[] args) {
45+
// accessing Inner class
46+
OuterClass obj1 = new OuterClass(10, 20, 30, 40);
47+
obj1.show();
48+
OuterClass obj2 = new OuterClass(10, 50, 30, 40);
49+
obj2.show();
50+
// Inner inner = new Inner();
51+
//System.out.println(inner.display());will generate compilation error as inner class can be accessed only inside the block it belongs to
52+
53+
}
54+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /