Skip to content
Home » Java Programing Language » Package & Import statements | Access Modifier In Java

Package & Import statements | Access Modifier In Java

Package Statement

  1. Package is a collection of java classes.
  2. By creating package code will become easy to manage and develop.
  3. The classes with similar functionality can be combine an place inside a same package.
  4. Package statement must be a first statement in a source file.
  5. Syntax :

package pack1.pack2.pack3;

  1. Package statement is applicable for all the class present inside a source file.
  2. There can be only once package statement for a source file.

 

Import statement

  1. Is use to access the class from one package to another.
  2. Import statement must be a 2nd statement after package.
  3. Can have more than one import statement in a source file.
  4. Import statement is applicable for all the java classes in a source file.
  5. Syntax

import pack1.pack2.ClassName;

the above import statement can be use to import only single class from a package

import pack1.pack2.*;

the above import statement can be use to import all the classes from a package

 

Access Modifier

  1. It is use to manage the access of the properties of the class.
  2. There are 4 access modifier
    1. private
    2. protected
    3. public
    4. default/package

Access Modifier

Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:

  • At the top level—public, or package-private (no explicit modifier).
  • At the member level—publicprivateprotected, or package-private (no explicit modifier).

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.)

At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

 

 

Join Telegram : Click Here

 

All Full Stack Java Study Material

 

Java the programing language

 

Job’s For Fresher

 

Share This Information To Your Friends and Your College Group’s, To Help Them !