Asked • 03/29/21

I am getting an error that constructor "cannot be applied to given types"

Given this code:


Main.java

class Main {
public static void main(String[] args) {
SpecificThing mine = new SpecificThing();
System.out.println(mine.double_my_number());
}
}


Anything.java

public class Anything {
private int my_number;

public Anything(int a) {
my_number = a;
}

public int get_my_number() {
return my_number;
}
}


SpecificThing.java

public class SpecificThing extends Anything {
public int double_my_number() {
return get_my_number() * 2;
}
}


The editor highlights SpecificThing with the error:

Implicit constructor Anything() is undefined for default constructor. Must define explicit constructor


and the compiler reports the following error:

SpecificThing.java:1: error: constructor Anything in class Anything cannot be applied to given types;
public class SpecificThing extends Anything {
^
required: int
found: no arguments
reason: actual and formal argument lists differ in length


What does that all mean and how do I fix my code?

2 Answers By Expert Tutors

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.