class Computer
{
private String companyName;
private double price;
public Computer(String companyName, double price)
{
this.companyName = companyName;
this.price = price;
}
public void show()
{
System.out.println("Company name : "+companyName);
System.out.println("Price : "+price);
}
}
class Desktop extends Computer
{
String color;
double monitorSize;
String processorType;
public Desktop(String companyName, double price, String color, double monitorSize, String processorType)
{
super(companyName, price);
this.color = color;
this.monitorSize = monitorSize;
this.processorType = processorType;
}
@Override
public void show() {
super.show();
System.out.println("Color: "+color);
System.out.println("Monitor size: "+monitorSize);
System.out.println("Processor type: "+processorType);
}
}
class Laptop extends Computer
{
String color;
double size;
double weight;
String processorType;
public Laptop(String companyName, double price, String color, double size, double weight, String processorType)
{
super(companyName, price);
this.color = color;
this.size = size;
this.weight = weight;
this.processorType = processorType;
}
@Override
public void show() {
super.show();
System.out.println("Color: "+color);
System.out.println("Size: "+size);
System.out.println("Weight: "+weight);
System.out.println("Processor type: "+processorType);
}
}
public class Main {
public static void main(String[] args)
{
Computer computer = new Computer("Company",1000);
computer.show();
System.out.println();
Computer desktop = new Desktop("Company2",1500,"black",105,"Intel");
desktop.show();
System.out.println();
Computer laptop = new Laptop("Company3",1200,"white",55,1,"Processor");
laptop.show();
}
}
Comments
Leave a comment