java tutorial

java tutorial

Java Packages


A group of similar types of classes, interfaces and sub-packages are called Java Packages

There are two forms of package:

  • Built-in package
  • User-defined package.

Some of the built-in packages are: java, lang, awt, javax, swing, net, io, util, sql etc.

User- Defined Packages

User-defined packages are made using ‘package’ keyword irrespective of using import

Access Modifiers

The access modifiers define the accessibility (scope) of a data member, functions or class.

Following are the types of java access modifiers:

  • Public
  • Private
  • Protected
  • Default

For Example:

package packexample;  
public class A{  
  public void msg(){System.out.println("Package Example");}  

package mypackexample;  
import packexample.*;  

class B{  
  public static void main(String args[]){  
   A obj = new A();  

Output: Package Example

Leave a Reply

Your email address will not be published. Required fields are marked *