-
Notifications
You must be signed in to change notification settings - Fork 0
/
06.txt
74 lines (57 loc) · 3.04 KB
/
06.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.Scanner;
abstract class Vehicle {
protected String model;
protected int price;
protected int cc;
public abstract void getDetails();
public abstract void displayDetails();
}
class Car extends Vehicle {
public void getDetails() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Car details:");
System.out.print("Enter model: ");
model = scanner.nextLine();
System.out.print("Enter price: ");
price = scanner.nextInt();
System.out.print("Enter CC: ");
cc = scanner.nextInt();
}
public void displayDetails() {
System.out.println("\nCar Details:");
System.out.println("Model: " + model);
System.out.println("Price: " + price);
System.out.println("CC: " + cc);
System.out.println();
}
}
class Bike extends Vehicle {
public void getDetails() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Bike details:");
System.out.print("Enter model: ");
model = scanner.nextLine();
System.out.print("Enter price: ");
price = scanner.nextInt();
System.out.print("Enter CC: ");
cc = scanner.nextInt();
}
public void displayDetails() {
System.out.println("\nBike Details:");
System.out.println("Model: " + model);
System.out.println("Price: " + price);
System.out.println("CC: " + cc);
}
}
public class AbstractExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Vehicle car = new Car();
car.getDetails();
car.displayDetails();
Vehicle bike = new Bike();
bike.getDetails();
bike.displayDetails();
scanner.close();
}
}