Program to create package named "myPackage" and put "DisplayMsg" class in it

In this program, we have created a package myPackage and put the DisplayMsg class in that package. Compile this program using java compiler then you will get a .class file in given package.


PROGRAM
package myPackage;

public class DisplayMsg
{
 public void show()
 {
  System.out.println("This is from package.");
 }
}
HOW TO COMPILE ?

To compile the above package program use the following command.
javac  -d  .  DisplayMsg.java
After successful compilation the myPackage directory will be created and the .class file is placed in that directory. The output of this program is the .class file.

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