Monday, 20 July 2015

SIMPLE PROGRAMME TO CREATE A PACKAGE AND TO RECALL IT IN A PROGRAMME.

programme:-to create a package and save all class file in it and to recall it in using other file.
First of  all write a programme like this or what you want only write a (package name;)
on top

package abc2;
public class simple
{
int x;
//simple()
{
x=45;
}
public void disp()
{
System.out.println("value of x"+(x));
}
}

save it by simple.java
open CMD
1) javac simple.java             (press enter)
2) javac -d . simple.java             (press enter)

A class file is created along with a folder name abc2,,
now how to recall simple class file form package abc2,
let see,

import abc2.simple;
public class notepad
{
public static void main(String args[])
{
simple s=new simple();
s.disp();
}
}

to recall class file in package only write (import package name.class file name;)

No comments:

Post a Comment