why an outer class cannot be declared as private?

Answers were Sorted based on User's Feedback



why an outer class cannot be declared as private?..

Answer / ravi kumar

private class PrivateClass //You cannot use private here
{
}


class TestClass //This is valid
{
}
}
This is because, in above example, if you declare PrivateClass as private then it's private to what? As Vijay said, it is of no use. So, intellisense intelligently doesn't show 'private' .

also another thing that private class can not be instantiate means u can not create object that class then what will be use of that class

Is This Answer Correct ?    5 Yes 0 No

why an outer class cannot be declared as private?..

Answer / Vikalp Chauhan

An outer class cannot be declared as private because a private outer class would restrict access to its methods and fields only within the same package. However, a private inner or nested class can be defined, which is only accessible within its enclosing class.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What are the access modifiers in java?

1 Answers  


Is array a class?

1 Answers  


What is a singleton factory?

1 Answers  


Q) I have a ArrayList object, in that object i have added 5 integer values, 5 float values, 5 string values. Now question is how can delete particular type of data ( i.e all int values or all float values or string values) in that list object at a time?

3 Answers   Aricent,


Define immutable object?

1 Answers  


Explain the difference between the Boolean & operator and the && operator?

1 Answers  


Which software is used for java programming?

1 Answers  


What is hasnext in java?

1 Answers  


What does string [] args mean?

1 Answers  


Which containers use a FlowLayout as their default layout?

3 Answers  


What is a variable simple definition?

1 Answers  


Why set do not allow duplicates in java?

1 Answers  


Categories