ㅤㅤ

What Are Packages In Java | what is package in java with example

what are packages in java | what is package in java with example

What Are Packages In Java | what is package in java with example

What are packages?

Packages group related classes and interfaces together and thus avoiding any name conflicts. From OOP's point of view packages are useful for grouping related classes together. Classes are group together in a

package using "package" keyword. Below is a sample snippet for a package which groups "Class!" and "Class2" in one package "Package1".

In "clsRun" class we have created objects of "Class!" class which exist in "packagel" as well as "package2". There are two things which is important to be noted one is the "import" keyword at the top of the class and second is both objects are created using "PackageName.Classname". For instance "objplclass!" object is created using "Package1.Class!". You can see that we can have class with same

name but they lie in different packages. For instance in the above example "Class!" name is give two files but they lie in different packages. Normally in big projects where we have huge amount of classes its better to group them logically together so that the project can be manageable.

what is package in java with example


  1. //save as Simple.java  
  2. package mypack;  
  3. public class Simple{  
  4.  public static void main(String args[]){  
  5.     System.out.println("Welcome to package");  
  6.    }  
  7. }  

what are packages in java | what is package in java with example

Post a Comment

Thanks for Comment

Previous Post Next Post