ADDING A CLASS TO A PACKAGE
It is simple to add a class t an existing package. Consider the following packages –
Package p1;
pclass a
{
------------------------------------
------------------------------------
}
The package p1 contents 1 public class by name a. Suppose we want to add another class b to the package . This can be done as follows –
1. Define a class and make it public.
2. Place the package statement.
Before the class definition as follows-
Package p1;
public class b
{
------------------------------
------------------------------
---------------------------------
}
3. Store this as b.java file under the directory p1.
4. Compile b.java file. This will create a b.class file and place it in the directory p1. Here we can also add a non public class to package using the same procedure. Now the package p1 the contain the both class a and b the statement like –
Import p1.*;
Will import both of them.
No comments :
Post a Comment