100% found this document useful (1 vote)
948 views

Hiding Class in Java

Only classes declared as public in an imported package will be accessible to programs importing that package. Classes not declared as public will be hidden from importing programs. For example, if a class is not declared as public within a package, it can only be seen and used by other classes within that same package and will be hidden from classes outside the package.

Uploaded by

mahima yadav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
948 views

Hiding Class in Java

Only classes declared as public in an imported package will be accessible to programs importing that package. Classes not declared as public will be hidden from importing programs. For example, if a class is not declared as public within a package, it can only be seen and used by other classes within that same package and will be hidden from classes outside the package.

Uploaded by

mahima yadav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java-Hiding Classes

December 16, 2015 by Java Tutorial


Hiding Classes
When we import a package within a program, only the classes declared as public in that package
will be made accessible within this program. In other words, the classes not declared as public in
that package will not be accessible within this program.
We shall profitably make use of the above fact. Sometimes, we may wish that certain classes in a
package should not be made accessible to the importing program. In such cases, we need not
declare those classes as public. When we do so, those classes will be hidden from being accessed
by the importing class. Here is an example :

Here, the class DataClass which is not declared public is hidden from outside of the
package mypack. This class can be seen and used only by other classes in the same package.
Note that a Java source file should contain only one public class and may include any number
of non-public classes.
Program

You might also like