Wednesday, November 21, 2012

PACKAGES in java

PACKAGES Student Deatils


//Main Program

import p1.*;
import p2.*;
class stu
{
public static void main(String args[])
{
ug u=new ug(4,"Vikram","bca");
pg p=new pg(6,"Vikram","mca");
u.show();
p.display();
}
}


//PACKAGE-1
package p1;
public class ug
{
int rollno;
String name,branch;
public ug(int r,String n,String b)
{
rollno=r;
name=n;
branch=b;
}
public void show()
{
System.out.println("UG Student Details:");
System.out.println("Rollno="+rollno);
System.out.println("Name="+name);
System.out.println("Branch="+branch);
}
}


//PACKAGE-2
package p2;
public class pg
{
int rollno;
String name,branch;
public pg(int r,String n,String b)
{
rollno=r;
name=n;
branch=b;
}
public void display()
{
System.out.println("PG Student Details:");
System.out.println("Rollno="+rollno);
System.out.println("Name="+name);
System.out.println("Branch="+branch);
}
}

0 comments:

Post a Comment