Monday, 28 November 2016

Program to create a package named 'useFullToo' inside the above package 'useFul' with one class named 'useMeToo' having a method to display the message "This is from Inside Package"

Packages can contain sub packages (one package in another package). In simple words you can create a hierarchy of packages using dot (.) operator as given below:
package p1.p2.p3;  

In above example the package p1 is main package, p2 is sub-package of p1 and p3 is sub-package of p2.

In this program, we have created a package useFullToo inside the existing package named useFul and put the UseMeToo class in that package. Compile this program using java compiler then you will get a .class file in given package.


PROGRAM
package useFul.useFullToo;

public class UseMeToo
{
 public void display()
 {
  System.out.println("This is from Inside Package.");
 }
}
OUTPUT
C:\>javac -d . UseMeToo.java

No comments:

Post a Comment