aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why a regular class cannot be protected. 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 "Why a regular class cannot be protected." Watch "Why a regular class cannot be protected." New topic
Author

Why a regular class cannot be protected.

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi, Why a regular class cannot be protected.


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Harikrishna Gorrepati wrote:Hi, Why a regular class cannot be protected.

You can use the same modifiers for inner classes that you use for other members of the outer class. For example, you can use the access specifiers — private, public, and protected — to restrict access to inner classes, just as you do to other class members.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi Abimaran, I am not clear. I am referring basic helloworld class which cannot have protected access specifier. what is the reason.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Harikrishna Gorrepati wrote:Hi Abimaran, I am not clear. I am referring basic helloworld class which cannot have protected access specifier. what is the reason.

Please => TellTheDetails <=.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

What is the use of assigning protected access to a top level class?? What purpose would it serve??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
So that super(Parent) class can be accessed in different packages



Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Oh My Bad, I confused with the regular and the regular inner class. Sorry Harikrishna Gorrepati, I confused you.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

For this purpose, you can use/make the Parent class' Constructor as protected!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why a regular class cannot be protected.