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

Popular posts from this blog

Program to define a class 'employee' with data members as empid, name and salary. Accept data for 5 objects using Array of objects and print it.

Define a class Student with four data members such as name, roll no.,sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also calculate total marks and percentage scored by student.

Program to input age from user and throw user-defined exception if entered age is negative