How to add a new Class to a Package?
https://www.computersprofessor.com/2016/12/how-to-add-new-class-to-package.html
Adding a class to a package:
It
is simple to add a class to an existing package.consider
the following package.
package p1;
public classA
{
Body of A
}
The
package p1 contains one public class by name A.suppose we want to add another
classB to this package.this can be done as follows:
·
Define
the class and make it public
·
Place
the package statement
package
p1;
Before
the class definition as follows:
package
p1;
public
classB
{
Body
of B
}
·
Store
this as B.java file under the directory P1.
·
Compile
B.java file. this will create a B class file and place it in the directory P1.
Note that we can also add a non public
class to a package using the same procedure.
Now,the package P! Will contain both the classes A and B.a
statement like
import
P1.*;
Will import both of them