Advertisement
class OuterC
{
int a=10; //outerC member variable
static class NestedC //Static Nested Class
{
public void method()
{
System.out.println("method of static NestedInner1 class");
System.out.println("Accessing outer class member variable = "+a);
}
}
public static void main(String... ar)
{
NestedC ob= new NestedC();
ob.method();
}
}
Static1.java:9: error: non-static variable a cannot be referenced from a static
context
System.out.println("Accessing outer class member variable = "+a)
;
^
1 error
Advertisement
class OuterC
{
static class NestedC
{
public void nestedMethod()
{
System.out.println("method of static nested class class");
}
}
public static void main(String... ar)
{
NestedC ob= new NestedC();
ob.method();
}
}
method of static nested class
class B
{
static class NestedC
{
public void nestedMethod()
{
System.out.println("method of static nested class");
}
}
}
class A
{
public static void main(String... ar)
{
B.NestedC ob2 = new B.NestedC();
ob2.method();
}
}
method of static NestedInner2 class
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement