I have a product. I am using a previous class, as the only difference between prior and now, is that there is the option of a 10% discount (float 0.1) which can be multiplied by the price, if the order quantity exceeds 10 units.
I extended the Product class using DisountedProduct as the inherited class, but when I call the constructor from the parent class, I get the error "Invalid method declaration, return type required."
I have read the java explanation of inheritance but It doesn't mention this.
Please help
public class DiscountedProduct extends Product {
private float discount;
private String name;
private double price;
private int quantity;
public Product(String name, double price, int quantity){
this.name = name;
this.price = price;
this.quantity = quantity;
}
//Get//
public float getDiscount(){
return discount;
}
//Set//
public void setDiscount(float value){
this.discount = value;
}
}
public class Product {
private String name;
private double price;
private int quantity;
public Product(String name, double price, int quantity){
this.name = name;
this.price = price;
this.quantity = quantity;
}
//Get Methods//
public String getName(){
return name;
}
public double getPrice(){
return price;
}
public int getQuantity(){
return quantity;
}
public double getTotalPrice(){
return quantity * price;
}
//Set Methods//
public void setName(String value){
this.name = value;
}
public void setPrice(double value){
this.price = value;
}
public void setQuantity(int value){
this.quantity = value;
}
}