Controlling Access to Members of a Class - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Controlling Access to Members of a Class

Description:

... whether other classes can use a particular field or invoke a particular method. ... (package-private) just as with top-level classes, and with the same meaning. ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 9
Provided by: admi2073
Category:

less

Transcript and Presenter's Notes

Title: Controlling Access to Members of a Class


1
Controlling Access to Members of a Class
2
Access control 1
  • Access level modifiers determine whether other
    classes can use a particular field or invoke a
    particular method. There are two levels of access
    control

3
Access control 2
  • At the top levelpublic, or package-private (no
    explicit modifier).
  • At the member levelpublic, private, protected,
    or package-private (no explicit modifier).

4
Access control 3
  • 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 (packages
    are named groups of related classes).

5
Access control 4
  • 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.

6
Access control 5
  • The private modifier specifies that the member
    can only be accessed in its own class.

7
Access control 6
  • 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.

8
Access control 7
  • http//java.sun.com/docs/books/tutorial/java/javaO
    O/accesscontrol.html
Write a Comment
User Comments (0)
About PowerShow.com