0

It is the basic doubt that I am asking. Before asking here I asked with some of my colleagues and even with google but none returned me the answer which convinced me. So please anyone clarify my doubt. Thank you.

Beryllium
  • 12,808
  • 10
  • 56
  • 86
Rajesh Acharya
  • 214
  • 2
  • 10

1 Answers1

1

yes. private is an access modifier, as you might have learned that restricts member to be access just within declaring scope. So as a member of another class, private class can be accessed in that class only.

Note that the top level classes can never be private

class Test {
private class TestInner{

}
....
TestInner ti = new TestInner();
....
}
Ankit
  • 6,554
  • 6
  • 49
  • 71
  • So only for inner private class we can create objects for not for outer private class? – Rajesh Acharya Sep 02 '13 at 10:30
  • 1
    @RajeshAcharya: There is no outer private class. If you try, the compiler will tell you `Illegal modifier for the class YOURCLASSNAME; only public, abstract & final are permitted`. – jlordo Sep 02 '13 at 10:33
  • @RajeshAcharya top level classes can never be private – Ankit Sep 02 '13 at 10:35