Java class visibility

Posted on 2006-04-14
Last Modified: 2010-05-18
With regards to the following statement:
Normal (non-inner) classes cannot be made private or protected; they may only be given public or package access.

1)Is this because otherwise no other classes could be derived from it? Are there other reasons?

2) I thought "protected" meant only package access???
Question by:kellyputty
    LVL 86

    Accepted Solution

    >>1)Is this because otherwise no other classes could be derived from it? Are there other reasons?

    It's because they wouldn't be visible.

    2. No - they're quite different:

    Author Comment

    LVL 86

    Expert Comment

    LVL 1

    Expert Comment

    1. There is not point in making a non-inner class private. If there was a non-inner private class it means that the class can be used only by itself and none other. No use of a such an isolated self service class.

    2. Protected means access within the package and also by sub-classes. Protected is primarily for inheritence. So it makes sense to have members of a class as protected not the class itself.

    here is the accessor hierarchy in Java

    Private - within the class
    Package - within the package
    Protected - within package and sub-classess
    Public - every where

    Author Comment


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    fetching the full url inside controller 2 31
    userCompare  challenge 3 55
    array220 challenge 8 32
    count11 challenge 6 35
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This video teaches viewers about errors in exception handling.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now