Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Protected class

 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there such thing as a class with the protected access modifier? I mean, can a class be defined visible only to its peers in the same package and subclasses of the outer-package-world? What are the modifiers that ca be applied to classes?

Any considerations are much welcome.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>Is there such thing as a class with the protected access modifier?
Well yes, inner classes can be protected. They could be private and static too (all these modifiers cannot be applied to Outer level classes)

>I mean, can a class be defined visible only to its peers in the same package and subclasses of the outer-package-world? What are the modifiers that ca be applied to classes?
High level classes/Outer classes/ie non-inner classes have only 2 modifiers - public or no modifier (public class X or class X). public classes are visible everywhere and the no-modifier one is visible only inside the pkg (to all sub-classes and non-sub-classes in the pkg).

Tx,
ram.
 
Yasith Vidanaarachchi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Top level classes can only be public and friendly, but there can be only one public class per one source file.these are the access modifiers that can be applied to a classes(Top level).

Yasith Vidanaarachchi
---------------------
SCJP 1.4
[ January 28, 2005: Message edited by: Yasith Vidanaarachchi ]
 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys!
 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just passed the SCJP1.4 exam and wanted to post this appreciation note to thank everyone who helped me understand Java a little better. Without your help this personal achievement wouldn't be possible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic