Guest User

Untitled

a guest
Jun 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. public class Vehicle {
  2. int vehicle_no;
  3. String model;
  4. String manufacturer;
  5. String color="yellow";
  6. public Vehicle(){
  7.  
  8. }
  9.  
  10. public Vehicle(int vehicle_no, String model, String manufacturer, String color) {
  11. this.vehicle_no=vehicle_no;
  12. this.model=model;
  13. this.manufacturer=manufacturer;
  14. this.color=color;
  15. }
  16.  
  17. }
  18. ________________________________________________________
  19.  
  20. public class Truck extends Vehicle{
  21. int loadingCapacity=100;
  22.  
  23. public Truck(){
  24.  
  25. }
  26.  
  27. public Truck(int vehicle_no, String model, String manufacturer, String color, int loadingCapacity) {
  28. super(vehicle_no,model,manufacturer,color);
  29. this.loadingCapacity=loadingCapacity;
  30. }
  31.  
  32. void display(){
  33. System.out.println("Vehicle Number: "+vehicle_no);
  34. System.out.println("Model: "+model);
  35. System.out.println("Manufacturer: "+manufacturer);
  36. System.out.println("Loading Capacity is: "+loadingCapacity);
  37. System.out.println("Color is: "+color);
  38. }
  39.  
  40.  
  41. }
  42. _____________________________________________________________
  43. public class Application {
  44. public static void main(String args[]){
  45. Scanner scanner=new Scanner(System.in);
  46. System.out.println("Truck no. is: ");
  47. int vehicle_no=scanner.nextInt();
  48.  
  49. System.out.println("Model is: ");
  50. String model=scanner.next();
  51.  
  52. System.out.println("Manufacturer is: ");
  53. String manufacturer=scanner.next();
  54.  
  55. System.out.println("Color is: ");
  56. String color=scanner.next();
  57.  
  58. System.out.println("Loading capacity is: ");
  59. int loadingCapacity=scanner.nextInt();
  60.  
  61. Vehicle vehicle=new Vehicle();
  62. System.out.println();
  63. System.out.println("Before changing color is: "+vehicle.color);
  64. Truck truck1=new Truck();
  65. Truck truck=new Truck(vehicle_no,model,manufacturer,color,loadingCapacity);
  66. System.out.println("Previous capacity is: "+truck1.loadingCapacity);
  67. System.out.println("\nTruck details");
  68. truck.display();
  69. scanner.close();
  70.  
  71. }
  72.  
  73. }
Add Comment
Please, Sign In to add comment