Saturday, 2 June 2012

Example for user defined package

Example for  user defined package 



package p1;
class c1
{
public void m1(){
System.out.println("Method m1 of Class c1");
}
public static void main(String args[]){
c1 obj = new c1();
obj.m1();
}
}
             

use this package
  before compile the package to create the package



save the program as sample.java

the in cmt box compile the program


javac - d . sample.java



then our package is created


Use this package to our program




import p1.*;
class c3
{
public   void m3()
{
System.out.println("Method m3 of Class c3");
}
public static void main(String args[])
{
c1 obj1 = new c1();
obj1.m1();
}
}





No comments:

Post a Comment