0

How do we create packages in Java?

Everything about packages in Java

28th Dec 2018, 5:07 PM
BHARTI ANIL PATEL
3 Answers
+ 2
Visualize this before you read further let's say you have a folder named "xyz". In this "xyz" folder you have two things : Main.java file and a folder named "abcd". Inside this "abcd" folder there is a A.java file. "xyz" -> Main.java "xyz" -> "abcd" -> A.java Now a package is a collection of classes. In the above example "abcd" is the package which contains A.java which in turn contains classes. user-defined packages are created using the package keyword followed by the package name where package name is nothing but the folder name classes of a package are imported using the import keyword eg)//A.java package abcd; public class A { public void display() { System.out.print("BHARTI ANIL PATEL"); } } //Main.java import abcd.A; public class Main { public static void main(String args[]) { new A().display(); } }
28th Dec 2018, 9:05 PM
Rishi Anand
Rishi Anand - avatar
0
Ahaaa, now I get some idea about this. Thank you!
28th Dec 2018, 11:54 PM
BHARTI ANIL PATEL