Code, showing the use of Inheritance, paramaterised constructors etc.
class staff
{
int code;
String name;
staff(int a, String b)
{
code=a;
name=b;
}
}
class t extends staff
{
String sub;
t(int a,String b,String c)
{
super(a,b);
sub=c;
}
}
class nt extends staff
{
String skill;
nt(int a,String b,String d)
{
super(a,b);
skill=d;
}
}
class x9
{
public static void main(String[] s)
{
t ob1=new t(111,"XYZ","MATH");
nt ob2=new nt(222,"ABC","XXX");
System.out.println("Teacher:-\nName: "+ob1.name+"\nCode: "+ob1.code+"\nSubject: "+ob1.sub);
System.out.println("\nTeacher:-\nName: "+ob2.name+"\nCode: "+ob2.code+"\nSubject: "+ob2.skill);
}
}
Thursday, August 16, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment