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.
Asked
Active
Viewed 6,415 times
0
-
Very unclear: Are you trying to instantiate a private class? Something else? – nanofarad Sep 02 '13 at 10:28
-
2Well, if you couldn't - what would be the use of a private class? – jlordo Sep 02 '13 at 10:28
-
Yes trying to instantiate private class – Rajesh Acharya Sep 02 '13 at 10:32
-
@RajeshAcharya have you tried writing same, you will get compilation error for outer class. – Panther Dec 06 '14 at 20:50
1 Answers
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
-