wood burning stoves 2.0*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 6662
    
    5

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 - More SCJP Mocks
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

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