JAVA
java
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
// Define a class representing a generic product
class Product {
private String name; // Name of the product
private double price; // Price of the product
// Constructor to initialize name and price
public Product(String name, double price) {
this.name = name;
this.price = price;
}
// Getter method for retrieving the product name
public String getName() {
return name;
}
// Getter method for retrieving the product price
public double getPrice() {
return price;
}
// Method to calculate the total price after applying a 5% tax
public double calculateTotalPrice() {
return price * 1.05; // 5% tax
}
}
// Define a subclass representing an electronic product
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run