0
public class Monitor extends Peripheral {
    public Monitor(){
        super();
    }
    public Monitor (String name,String maker, int age, int price,String type,int size,String res,String ports){
        super(name,maker,age,price);
        this.type = typel
        this.size = size;
        this.res = res;
        this.ports = ports;
    }
}

This is the the child class.I want to make it so that I can create a monitor object without giving it any parameters. These are the classes of its parents:

public class Product {
    protected String name, maker;
    protected int age,price;
    public Product(){}
    public Product(String name,String maker, int age, int price){
        this.name = name;
        this.maker = maker;
        this.age = age;
        this.price = price;
    }
}
public class Peripheral extends Product {
    //basically nothing here
    private static double discount = 0;
    public static void setDiscount(double disc){
        discount = disc;
    }
    public static double getDiscount(){
        return discount;
    }
}

The compiler says:error: constructor Peripheral in class Peripheral cannot be aplied to given types; super(); required: String,String,int,int found: no arguments

  • `super(...)` in `Monitor` delegates call to `Peripheral` constructor which doesn't have such signature. Perhaps, you need to define it. – J-Alex May 04 '18 at 16:24

3 Answers3

0

There is no constructor with Peripheral parametars!

Peripheral(String name, String maker, int age, int price)
mario
  • 111
  • 2
  • 3
  • 8
0

Peripheral does not inherit constructor from Product, you need to declare it explictly:

public class Peripheral extends Product {

    public Peripheral(String name,String maker, int age, int price) {
        super(name,maker,age,price);
    } 

    //....
}
xingbin
  • 27,410
  • 9
  • 53
  • 103
0

first of all, you have a typo in here:

public Monitor (String name,String maker, int age, int price,String type,int 
size,String res,String ports){
    super(name,maker,age,price);
    this.type = typel <--- here(nasty semi-colons)

I think you will forcefully have to create a product object before your monitor object as you will be missing those super parameters which your monitor is trying to get.

A work around is, you might want to create another constructor that doesn't have the super(params); so that way it will get rid of that error you are getting.

so instead of your constructor, you should do something like this:

public Monitor (String type,int size,String res,String ports){
    this.type = type;
    this.size = size;
    this.res = res;
    this.ports = ports;
}

hope this solves your issue!

SkiiNet
  • 67
  • 1
  • 8
  • The issue here is that I want to create an empty Monitor object (taking no parameters) but I don't seem to be able to becuase something is up with the super(). Thanks anyway. –  May 04 '18 at 17:42
  • where exactly do you want to create it? – SkiiNet May 04 '18 at 19:37