Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Question6Main {
- public static void main(String[] args) {
- ElectricalProduct ep=new ElectricalProduct(200, 30, 5, "abc", 123, 2100);
- ep.display();
- }
- //
- public class ElectricalProduct extends Product {
- int wattage;
- int voltageRange;
- int price;
- ElectricalProduct(int wattage,int voltageRange,int productId,String name,int categoryId,int unitPrice){
- super(productId, name, categoryId,unitPrice);
- this.wattage=wattage;
- this.voltageRange=voltageRange;
- }
- void display()
- {
- System.out.println("Before modifications");
- System.out.println("Product id "+productId+" product name: "+name+" category id "+categoryId+" unit price "+unitPrice+" wattage"+wattage+" voltageRange"+voltageRange);
- Product p=new Product();
- p.unitPrice=10;
- wattage=400;
- System.out.println("After Modifications");
- System.out.println("Product id "+productId+" product name: "+name+" category id "+categoryId+" unit price "+p.unitPrice+" wattage"+wattage+" voltageRange"+voltageRange);
- }
- }
- //
- public class Product
- {
- int productId;
- String name;
- int categoryId;
- int unitPrice;
- Product(){}
- Product(int productId,String name,int categoryId,int unitPrice)
- {
- this.categoryId=categoryId;
- this.name=name;
- this.productId=productId;
- this.unitPrice=unitPrice;
- }
- }
Add Comment
Please, Sign In to add comment