Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Inheritance in Java Inheritance in Java Object Equality

trying to add a parameter to a constructor but getting a message

trying to add a String parameter but keep getting an err message when instantiating the object

I keep getting this err msg

Main.java:14: error: constructor Animal in class Animal cannot be applied to given types;
  required: no arguments
  found: String
  reason: actual and formal argument lists differ in length
1 error
compiler exit status 1


class Main {
    public static void main(String[] args) {
        Dog Loki = new Dog("Woof");
        Dog Thor = new Dog("Bark");

abstract class Animal {
    String sound = "";

class Dog extends Animal {
    Dog(String sound) {

1 Answer

Daniel Turato
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,124 Points

The Animal abstract class has a single field sound but doesn't have any methods or constructors, only the default Animal() constructor. So when you call super(sound) in the Dog class it won't work as you trying to call a constructor that doesn't exist. So you can do something like this:

Dog(String sound) {
  this.sound = sound