Question: This is the previous code: public class Testmain { public static void main ( String [ ] args ) { Product objProduct = new Product

This is the previous code:
public class Testmain {
public static void main(String[] args){
Product objProduct = new Product("Generic Product", 50);
ElectronicsProduct objElectronicsProduct = new ElectronicsProduct("Laptop",1000,2,65);
System.out.println("Product information: ");
System.out.println(objProduct);
System.out.println("
Electronic product information: ");
System.out.println(objElectronicsProduct);
}
}
--------
class Product {
private String name;
private double priceRange;
public Product(String name, double PriceRange){
this.name = name;
this.priceRange = priceRange;
}
public double getPriceRange(){
return priceRange;
}
public String toString(){
return "Name: "+name+", Price Range: $"+ priceRange;
}
}
-------
class ElectronicsProduct extends Product{
private int warrantyPeriod;
private double powerConsumption;
public ElectronicsProduct(String name, double priceRange, int warrantyPeriod, double powerConsumption){
super(name, priceRange);
this.warrantyPeriod = warrantyPeriod;
this.powerConsumption = powerConsumption;
}
public int getWarrantyPeriod(){
return warrantyPeriod;
}
public double getPowerConsumption(){
return powerConsumption;
}
@Override
public String toString(){
return super.toString()+", Warranty period: "+warrantyPeriod+" years, Power consumption: "+powerConsumption+"watts";
}
}
This is the previous code: public class Testmain

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!