Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program to implement inheritance with super keyword
- class Vehicle
- {
- private String regNo;
- private int model;
- private String color;
- public Vehicle(String regNo,int model,String color)
- {
- this.regNo=regNo;
- this.model=model;
- this.color=color;
- }
- public String toString()
- {
- String out="Registration: "+regNo+"\nModel: "+model+"\nColor: "+color;
- return out;
- }
- }
- class Car extends Vehicle
- {
- private String type;
- private String company;
- public Car(String regNo,int model,String color,String type,String company)
- {
- super(regNo,model,color);
- this.type=type;
- this.company=company;
- }
- public String toString()
- {
- String out=super.toString();
- out+="\nType: "+type+"\nCompany: "+company;
- return out;
- }
- }
- class InheritanceTest
- {
- public static void main(String a[])
- {
- Vehicle veh1=new Car("TN 20 H 108",2008,"Silver","Sedan","Toyota");
- System.out.println("Details of the Car: \n"+veh1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement