Java tutorial- package |
|||||||||||||||||||||||||||
Java packageA package enables you to structure your files in folders and subfolders. By doing so, you can avoid file names conflict.-Create a folder called javasource in drive D: (D:\javasource) -Save the following code as TestInheritance.java in it import Testpackage.*;//to import the package named Testpackage
class Dog extends Animal
{
}
public class TestInheritance
{
}
-Create a subfolder called Testpackage in D:\javasource and save the following code as Animal.java in it.
package Testpackage; //to create a package named Testpackage abstract class Animal
{
}
-Type javac TestInheritance.java in DOS window to compile the program -Type java TestInheritance in DOS window to run the program
Note:
-all
package statement must be the first statement in the file
|
|||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||