Monday, January 13, 2014

Java Packages Programming Example 1

//Note:  Analysis the programs errors,outputs and Understand the Package concept in Java



//[1]
//package1
package pack1;
public class Cust{
int balance;
void seti(int bb){
balance=bb;
}
void print(){
System.out.println("balance="+balance);
}
}


//package2
package pack2;
public class Cust extends pack1.Cust{
public String name;
public void setname(String name){
this.name=name;
}
public void print(){
System.out.println("name="+name);
System.out.println("balance="+balance);
}
}






//importing package1,package2
import pack1.*;
import pack2.*;
class Test59{
public static void main(String arg[]){
pack1.Cust c1=new pack1.Cust();
c1.seti(5);
c1.print();
pack2.Cust c2=new pack2.Cust();
c2.setname("amar");
c2.print();
}
}
Post a Comment