Site Network: Home | About

If u r already much comfortable with access modifiers, I think u need not to scroll down.

Here is the summary of access specifiers...

Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:

  • At the top level-public, or package-private (no explicit modifier). - especially, at the Class level access modifier.
  • At the member level-public, private, protected, or package-private (no explicit modifier).

At the top level..., a class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package.

package mypack; private class HelloWorldParent { //is invalid. This should be public or default public HelloWorldParent(){} } -- I was not aware of this point earlier. Only this point made me to post this in my blog.

At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

The following table shows the access to members permitted by each modifier. You can find this typical information in any Java fundamental books.

Access Levels

Modifier Class Package Subclass World

public Y Y Y Y

protected Y Y Y N

default Y Y N N

private Y N N N

Hope this material would be helpful to u.

I've been finding difficulty in formatting the text and graphics in my blog. Hope I will find the solution soon...

-Karteeek

2 Comments:

  1. M.V.K said...
    enti maama no new posts!!
    Karteek said...
    work konchem ekkuvaga undesariki, konchem gap vachindhira. will be active from now on - again :) .

Post a Comment