Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. package saeed;
  2. import java.lang.*;
  3.  
  4. interface Vehicle
  5. {
  6. public double speed();
  7. public int isRunning();
  8.  
  9. }
  10.  
  11. class Land implements Vehicle
  12. {
  13. double spd=100;
  14. int running;
  15. public double speed()
  16. {
  17. return spd;
  18. }
  19. public int isRunning()
  20. {
  21. return running;
  22. }
  23. }
  24.  
  25. class Water implements Vehicle
  26. {
  27. double spd;
  28. int running;
  29. public double speed()
  30. {
  31. return spd;
  32. }
  33. public int isRunning()
  34. {
  35. return running;
  36. }
  37. }
  38.  
  39. class Air implements Vehicle
  40. {
  41. double spd;
  42. int running;
  43. public double speed()
  44. {
  45. return spd;
  46. }
  47. public int isRunning()
  48. {
  49. return running;
  50. }
  51. }
  52.  
  53. class Car extends Land
  54. {
  55. public double speed()
  56. { System.out.println("car speed "+spd);
  57. return 50;}
  58. public double superspeed()
  59. {
  60. return super.speed();
  61. }
  62. }
  63.  
  64. class Bus extends Land
  65. {
  66.  
  67. }
  68.  
  69. class Ship extends Water
  70. {
  71.  
  72. }
  73.  
  74. class Boat extends Water
  75. {
  76.  
  77. }
  78.  
  79. class Plane extends Air
  80. {
  81.  
  82. }
  83.  
  84. class Heli extends Air
  85. {
  86.  
  87. }
  88. public class main {
  89. Land landV = new Land();
  90. Car audi =new Car();
  91. {
  92.  
  93.  
  94. try
  95. {
  96. System.out.println("audi is instance od land");
  97. }
  98. catch (Exception e )
  99. {
  100. System.out.println("exception");
  101. }
  102.  
  103. System.out.println(audi.speed());
  104. System.out.println(audi.superspeed());
  105. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement