This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Top level class Vs inner classes access specifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Top level class Vs inner classes access specifiers" Watch "Top level class Vs inner classes access specifiers" New topic
Author

Top level class Vs inner classes access specifiers

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi,

Why top level class cannot be private or protected and inner classes can be private or protected?


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6588
    
    1

Because that is the way it is. What would you do with a top level private class ? Can you even use one ?


SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 431

inner classes have most strange concepts that are not applicable to regular class sometimes

like using abstract and static simultaneously (legal)

also other modifiers(private and protected) that applied only to inner class.(legal)


SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Arjun Srivastava wrote:
like using abstract and static simultaneously (legal)

Some inner class needs this behavior, but for outer classes, it doesn't make sense!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Gari Jain
Ranch Hand

Joined: Jun 29, 2009
Posts: 100
Harikrishna

Innerclasses are defined within another class and they are like members of the enclosing class. So just like the members of a class can be private or protected too, innerclasses can also be private or protected, just like methods of a class(because they are members of the class) can use the private members of the class, that is why innerclasses can also access the private members of the class.

One reason for the behaviour shown by innerclasses is because they are members of the enclosing class.


OCPJP 6-100%; Preparing for GATE11
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Top level class Vs inner classes access specifiers
 
Similar Threads
Errors due to private & protected top level class
Default constructor
private and protected modifier in top level class
private and protected class?
Question on protected access modifier