OOPJ-Notes-2-3
OOPJ-Notes-2-3
CHAPTER -3
PACKAGES
Contents
Introduction to Packages
Defining a Package
CLASSPATH
Access Protection
Importing Packages
References
INTRODUCTION TO PACKAGES
Package: In Java, a package is a container of classes, interfaces and sub-packages.
Packages are used to avoid naming conflicts and to organize project-related classes, interfaces
and sub-packages into a bundle.
In Java, the packages have divided into two types:
Build-in packages
User-defined packages
The package is both naming and visibility control mechanism.
DEFINING A PACKAGE
The keyword package is used to define a package.
package myPackage;
class MyClass{
public static void main(String args[]){
System.out.println(“MyClass in new package”);
}
}
ACCESS PROTECTION
Java addresses four categories of visibility for class members:
1. Subclasses in the same package
2. Non-subclasses in the same package
3. Subclasses in different packages
4. Classes that are neither in the same package nor subclasses
References:
1. Herbert Schildt, Java: The Complete Reference, 10thEdition, McGraw Hill
Education (India) Pvt. Ltd.
2. https://www.javatpoint.com/
3. http://www.btechsmartclass.com/java/java-tutorials.html