Inheritance in Java example 2
class rollno
{
int rollno;
rollno(int x)
{
rollno=x;
System.out.println(rollno);
}
}
class age extends rollno
{
int age;
age(int x,int y)
{
//super(x);
super.rollno();
age=y;
}
void show()
{
System.out.println("ROLLNO="+rollno+"\nAGE="+age);
}
}
class mark extends rollno
{
int mark;
mark(int x,int z)
{
super(x);
mark=z;
}
void display()
{
System.out.println("ROLLNO="+rollno+"\nMARK="+mark);
}
}
class conh
{
public static void main(String args[])
{
age ob1=new age(00,20);
ob1.show();
mark ob2=new mark(01,50);
ob2.display();
}
}
No comments:
Post a Comment