Guest User

Untitled

a guest
Jun 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public class Question6Main {
  2.  
  3.  
  4. public static void main(String[] args) {
  5. ElectricalProduct ep=new ElectricalProduct(200, 30, 5, "abc", 123, 2100);
  6. ep.display();
  7.  
  8. }
  9. //
  10. public class ElectricalProduct extends Product {
  11. int wattage;
  12. int voltageRange;
  13. int price;
  14.  
  15.  
  16. ElectricalProduct(int wattage,int voltageRange,int productId,String name,int categoryId,int unitPrice){
  17. super(productId, name, categoryId,unitPrice);
  18. this.wattage=wattage;
  19. this.voltageRange=voltageRange;
  20.  
  21.  
  22. }
  23.  
  24. void display()
  25. {
  26. System.out.println("Before modifications");
  27. System.out.println("Product id "+productId+" product name: "+name+" category id "+categoryId+" unit price "+unitPrice+" wattage"+wattage+" voltageRange"+voltageRange);
  28. Product p=new Product();
  29. p.unitPrice=10;
  30. wattage=400;
  31. System.out.println("After Modifications");
  32. System.out.println("Product id "+productId+" product name: "+name+" category id "+categoryId+" unit price "+p.unitPrice+" wattage"+wattage+" voltageRange"+voltageRange);
  33. }
  34.  
  35. }
  36. //
  37.  
  38.  
  39. public class Product
  40. {
  41. int productId;
  42. String name;
  43. int categoryId;
  44. int unitPrice;
  45.  
  46. Product(){}
  47. Product(int productId,String name,int categoryId,int unitPrice)
  48. {
  49. this.categoryId=categoryId;
  50. this.name=name;
  51. this.productId=productId;
  52. this.unitPrice=unitPrice;
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59. }
Add Comment
Please, Sign In to add comment