#12 Help :)


#1

I'm stuck at #12 and I have an error message that won't go away, it's
https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/inheritance?action=resume

The error message says

Dog.java:37: error: reached end of file while parsing
}
^
1 error

My code is:

class Dog {
 
  class Dog extends Animal{
  
    int age;
  
	public Dog(int dogsAge) {
    
  	age = dogsAge;
  }
  
  public void bark() {
		
    System.out.println("Woof!");
    
	}
	
  public void run(int feet) {
    
    System.out.println("Your dog ran " + feet + " feet!");

	}
  
  public int getAge() {

    return age;
    
	}
  
	public static void main(String[] args) {
    
    Dog spike = new Dog(5);
    spike.bark();
    spike.run(40);
    int spikeAge = spike.getAge();
    System.out.println(spikeAge);
     }

Thank you!


#2

class Dog {
 
  class Dog extends Animal{

dont need to write like that.you can extend from first line

  class Dog extends Animal{

and close the class here

public static void main(String[] args) {
    
    Dog spike = new Dog(5);
    spike.bark();
    spike.run(40);
    int spikeAge = spike.getAge();
    System.out.println(spikeAge);
     }

   // **here you have to close the  Dog class** //add } bracket

now complete the 2nd instruction


#3

class Dog extends Animal {

int age;

public Dog(int dogsAge) {
age = dogsAge;

}

public void bark() {

System.out.println("Woof!");

}

public void run(int feet) {

System.out.println("Your dog ran " + feet + " feet!");

}

public int getAge() {

return age;

}

public static void main(String[] args) {

Dog spike = new Dog(5);
spike.bark();
spike.run(40);
int spikeAge = spike.getAge();
System.out.println(spikeAge);
spike.checkStatus();

}

}

it shuld look like this...


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.