Repository navigation
Expand file tree
/
Copy pathecom.txt
More file actions
63 lines (47 loc) · 1.5 KB
/
Copy pathecom.txt
File metadata and controls
63 lines (47 loc) · 1.5 KB
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
class Product {
int id;
String name;
double price;
Product(int id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
void displayDetails() {
System.out.println("Product ID: " + id);
System.out.println("Name: " + name);
System.out.println("Price: $" + price);
}
}
class ElectronicProduct extends Product {
int warrantyInYears;
ElectronicProduct(int id, String name, double price, int warrantyInYears) {
super(id, name, price);
this.warrantyInYears = warrantyInYears;
}
void displayDetails() {
super.displayDetails();
System.out.println("Warranty: " + warrantyInYears + " years");
}
}
class ClothingProduct extends Product {
String size;
ClothingProduct(int id, String name, double price, String size) {
super(id, name, price);
this.size = size;
}
void displayDetails() {
super.displayDetails();
System.out.println("Size: " + size);
}
}
public class Ecommerce {
public static void main(String[] args) {
ElectronicProduct ep = new ElectronicProduct(101, "laptop", 850.0, 24);
ClothingProduct cp = new ClothingProduct(102, "jacket", 1999.0, "L");
System.out.println("Electronic Product Details:");
ep.displayDetails();
System.out.println("\nClothing Product Details:");
cp.displayDetails();
}
}