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

basic question on access modifiers and levels

 
Pran Pal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In the K&B 1.5 book, on page 68 (2 min drill), they wrote:
There are three access modifiers: public, protected, and private.
There are four access levels: public, protected, default, and private.


I'm a bit confused, Initially, I taught that both (modifier and level) were the same thing. But it doesn't looks like it.

What is the difference between an access modifier and access level?

thanks.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default access level does not have an access modifier.
 
Jay Ashar
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would you do if you want your class to be accessed only in package in which that class resides? You would not declare that class public and just declare the class without any keyword, which is default access.
So although your class does not have a keyword it still have an access-level.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic