Skip to content

Instantly share code, notes, and snippets.

@LunaticWolf
Created June 24, 2018 14:37
Show Gist options
  • Save LunaticWolf/5e62af6bafa275085dcc67da9a98c83f to your computer and use it in GitHub Desktop.
Save LunaticWolf/5e62af6bafa275085dcc67da9a98c83f to your computer and use it in GitHub Desktop.
3-6
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment