Guest User

Untitled

a guest
Jun 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. package day2;
  2. import java.util.Scanner;
  3.  
  4. class Vehicle
  5. {
  6. int noofwheels;
  7. int noofpassangers;
  8. int model;
  9. String make;
  10. public Vehicle()
  11. {
  12. this.noofwheels=4;
  13. noofpassangers=8;
  14. model=909;
  15. make="luxury";
  16. }
  17. public void display()
  18. {
  19. System.out.println("the " +
  20. "vehicle has:");
  21. System.out.println("make of the vehicle:" +make);
  22. System.out.println("model of the vehicle:" +model);
  23. System.out.println("no of wheels in the vehicle:" +noofwheels);
  24. System.out.println("no of passangers in the vehicle:" +noofpassangers);
  25. }
  26. }
  27. class Car extends Vehicle
  28. {
  29. int noofdoors;
  30. public Car()
  31. {
  32. super();
  33. noofdoors=4;
  34. }
  35. public void display()
  36. {
  37. super.display();
  38. System.out.println("the car has:");
  39. System.out.println("no of doors in car:" +noofdoors);
  40. }
  41. }
  42. class Convertible extends Car
  43. {
  44. boolean isHoodOpen;
  45. public Convertible()
  46. {
  47. super();
  48. isHoodOpen=true;
  49. }
  50. public void display()
  51. {
  52. super.display();
  53. System.out.println("the car is canvertible");
  54. System.out.println("is hood open in car:" +isHoodOpen);
  55. }
  56. }
  57. class SportCar extends Car
  58. {
  59. public SportCar()
  60. {
  61. noofdoors=2;
  62. }
  63. public void display()
  64. {
  65. super.display();
  66. System.out.println("the car is a sports car");
  67. }
  68. }
  69.  
  70. public class Q5
  71. {
  72.  
  73. public static void main(String[] args)
  74. {
  75. int a;
  76. Scanner sc=new Scanner(System.in);
  77. System.out.println("which method to be displayed");
  78. a=sc.nextInt();
  79. switch(a)
  80. {
  81. case 1:Vehicle v=new Vehicle();
  82. v.display();break;
  83. case 2: Car c=new Car();
  84. c.display(); break;
  85. case 3:Convertible cs=new Convertible();
  86. cs.display();break;
  87. case 4: SportCar sa=new SportCar();
  88. sa.display();break;
  89. }
  90. sc.close();
  91.  
  92. }
  93.  
  94. }
Add Comment
Please, Sign In to add comment