12: Inheritance Problem


#1

I seem to be having a hard time getting this question to work and I am not completely sure as to why my coding is not going through. I managed to get the first part of the question done and can't seem to get the rest of the section to go through.

Here is what I have for now:
class Dog extends Animal {

}
//This is where it says it went through for the first part of the question. I seem to be fine here.
public static void main(String[] args) {

Dog spike = new Dog(13);
spike.checkStatus();

//This is where I seem to be getting problems.

/* Currently Extra from the previous sections in this lesson.
spike.bark();
spike.run(25);

int spikeAge = spike.getAge();
System.out.println(spikeAge);
*/
}

I veiwed the example, reread the lesson and nothing seems to be correcting my mistake. There are a few errors being called out which I don't completely understand as they have been working the whole time.

Errors include:
Dog.java:21: error: class Dog is already defined in package unnamed package
class Dog extends Animal {
^
Dog.java:27: error: non-static variable this cannot be referenced from a static context
Dog spike = new Dog(13);
^
Dog.java:30: error: cannot find symbol
spike.bark();
^
symbol: method bark()
location: variable spike of type Dog.Dog
Dog.java:31: error: cannot find symbol
spike.run(25);
^
symbol: method run(int)
location: variable spike of type Dog.Dog
Dog.java:33: error: cannot find symbol
int spikeAge = spike.getAge();
^
symbol: method getAge()
location: variable spike of type Dog.Dog
5 errors

I would appreciate some form of explantion as to why things are not working, as well as a way to fix my mistakes.

Also the example has a ; missing from the statement, which I am not completely sure is needed or not and if it is missing and should be there request it gets fixed for the future:
Car myFastCar = new Car(2007) /* <-- right there no ; */
myFastCar.checkBatteryStatus();

Is this on purpose and it is the another reason why my coding is not working? I have tried without the ; as well but it says another error instead:
Dog.java:27: error: ';' expected
Dog spike = new Dog(13)
^
1 error

I can only assume from this that the coding does need the ; and that it couldn't be the reason but I decided to ask anyway so the problem might be fixed for anyone that also finds this to be an error.

I apprieciate the help and hope to here back soon. Sorry for how long this question is.


#2

@bbluefox130,
Maybe reading the Manual
https://docs.oracle.com/javase/tutorial/java/javaOO/classdecl.html


#3

The class Dog extends Animal { empty??????? } it is not too good. Fill it and if it wont working, go back to codacademy and come back with continue and try again.
This is a very good tool to learning languages and programming, but NOT PERFECT.


#4

@bbluefox130 ,

See the reply by @lajos.reisenleitnerg.

Your code starts as follows ...

class Dog extends Animal {

}

Due to that closing curly brace, none of the code that follows is part of that definition of the Dog class. You need to place all of the methods and variables within the Dog.java file into the Dog class.