Program to import package 'myPackage' and use the 'DisplayMsg' class in package

In previous program, we have crated a package named "myPackage" and added class "DisplayMsg" in that package. Now in this program we use that package to import the class "DisplayMsg" in class "PackageDemo".


PROGRAM
import myPackage.DisplayMsg;

class PackageDemo
{
 public static void main(String[] args)
 {
  DisplayMsg dm = new DisplayMsg();
  dm.show();
 }
}
OUTPUT
C:\>javac PackageDemo.java
C:\>java PackageDemo
This is from package.

Comments

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 draw Smiley in Applet