Here is (I think ...) the explanation of your problem :
try this code, you will not get a compilation error any more :
public class A {
class B {} // note than static is removed.
}
class C extends A.B {
// Added code BEGIN
C(A a) {
a.super();
}
// Added code END
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
The problem is that the compiler tries to provide a default Constructor to your class C. The default constructor looks like that :
C() {
super();
}
But this default constructor will not works, because in order to get an instance of A.B, you have first to get an instance of A.
You must then provide an instance of A.
Lahcen.
Originally posted by Balamurugan Kandasamy:
The following compiles.
import java.lang.*;
public class A {
[b]static class B {}
}
class C extends A.B {
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
But when I remove static for class B which is as below , it says
no enclosing instance of type A in scope.
import java.lang.*;
However if i dont extend A.B then it is not a problem.public class A {
class B {} // note than static is removed.
}
class C extends A.B {
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
import java.lang.*;
public class A {
static class B {}
}
class D {
public static void main(String args[])
{
A.B ab = new A().new B();
}
}
Think im not clear in this funda. Pls throw some light.
Thanks
MKBala...[/B]