abstract class Base
{
private int roll;
private String name;
private String branch;
Base(int roll,String name,String branch)
{
this.roll=roll;
this.name=name;
this.branch=branch;
}
int getRoll()
{
return roll;
}
String getName()
{
return name;
}
String getBranch()
{
return branch;
}
abstract void display(); // abstract Method
}
class Child extends Base
{
Child(int roll,String name,String branch)
{
super(roll,name,branch);
}
void display()
{
System.out.println("Name is : "+getName());
System.out.println("Roll number is : "+getRoll());
System.out.println("Branch is : "+getBranch());
}
}
class MainClass
{
public static void main(String[] args)
{
Base b=new Child(21,"sanjay","cse"); //upcasting
b.display();
}
}
Output
No comments:
Post a Comment