Package - Day 7 Flashcards
Package
A group of related classes, interfaces to help organisation
Package benefits
Modularisation
Reusable
Name conflicts
Controlled access
Data encapsulation
Two types of packages
Built in packages: predetermined packages that are a part of JDK.
User-Defined packages: developed by users in order to group related classes, interfaces and sub-packages
Keyword for package
package mypackage;
Can be used once and will package all interfaces and classes in the file.
Protected declaration
Protected Variables, methods & constructors can be accessed only by sub classes in other packages or any class within the package.
import keyword
Import built in or user defined packages
Import packagename.*;
^importe all classes
Import packagename.classname; ^imports only the class you want
Packagename.classname;
^ using it
Accessibility of access modifier
Public can be access anywhere
Private can be accessed only within that class
If not mentioned, element is accessible to all the classes in the same package
protected can be accessed to all classes inside the same package and to sub classes present in different package