Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package day2;
- import java.util.Scanner;
- class Vehicle
- {
- int noofwheels;
- int noofpassangers;
- int model;
- String make;
- public Vehicle()
- {
- this.noofwheels=4;
- noofpassangers=8;
- model=909;
- make="luxury";
- }
- public void display()
- {
- System.out.println("the " +
- "vehicle has:");
- System.out.println("make of the vehicle:" +make);
- System.out.println("model of the vehicle:" +model);
- System.out.println("no of wheels in the vehicle:" +noofwheels);
- System.out.println("no of passangers in the vehicle:" +noofpassangers);
- }
- }
- class Car extends Vehicle
- {
- int noofdoors;
- public Car()
- {
- super();
- noofdoors=4;
- }
- public void display()
- {
- super.display();
- System.out.println("the car has:");
- System.out.println("no of doors in car:" +noofdoors);
- }
- }
- class Convertible extends Car
- {
- boolean isHoodOpen;
- public Convertible()
- {
- super();
- isHoodOpen=true;
- }
- public void display()
- {
- super.display();
- System.out.println("the car is canvertible");
- System.out.println("is hood open in car:" +isHoodOpen);
- }
- }
- class SportCar extends Car
- {
- public SportCar()
- {
- noofdoors=2;
- }
- public void display()
- {
- super.display();
- System.out.println("the car is a sports car");
- }
- }
- public class Q5
- {
- public static void main(String[] args)
- {
- int a;
- Scanner sc=new Scanner(System.in);
- System.out.println("which method to be displayed");
- a=sc.nextInt();
- switch(a)
- {
- case 1:Vehicle v=new Vehicle();
- v.display();break;
- case 2: Car c=new Car();
- c.display(); break;
- case 3:Convertible cs=new Convertible();
- cs.display();break;
- case 4: SportCar sa=new SportCar();
- sa.display();break;
- }
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment