Contact Us || Privacy Policy || About Us |
|
Package in Java | Example→ Package in java encapsulate a group of classes, interface and sub package. ![]() Types of packages in Java:-
Advantage of Java Package
1) ExampleOutput ![]() How to Compile and run java package ExampleCompile: javac -d . A.java Run: java mypack1.A . dot for current directory -d Destination(where put class file) Note:- (Javac One Space -d again One space dot one space classname.java) How to access package from another package?There are following way. ![]() 2) without import(fully qualified name) A) Example : import the packagename.*Output ![]() Compile:- javac -d . A.java Compile: javac -d . Test.java Run : java mypack2.Test B) Example : import package.classnameOutput:- ![]() 2) Example Without importOutput:- ![]() Sub Package→ Package inside the Package is Called Sub package. Output:- ![]()
Next TopicAccess Modifiers in Java
|