Possible Duplicate:
protected/public Inner Classes
I am sure the question has been asked already, but I wasn't able to find one so I'll ask...
I am curious what is the difference between private(protected) and public inner class. I am able to use both from out of the containing class using the outer class object.
public class A{
private class B{
}
public static void main(String[] args){
A a = new A();
B b = a.new B();
}
}
A private inner class can still be accessed within the class that defined it.
If you have another class, B
isn't visible:
public class C {
public static void main(String[] args){
A a = new A();
B b = new B(); // compile error
}
}
Actually, you are inside class A still, since the main method is a static method of class A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With