Inheritance 12/13 Part 2


#1

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/inheritance?action=resume

Error Message: Dog.java:3: error: class Dog is already defined in package unnamed package
class Dog extends Animal {
^
Dog.java:11: error: cannot find symbol
age = dogsAge;
^
symbol: variable age
location: class Dog
Dog.java:29: error: cannot find symbol
return age;
^
symbol: variable age
location: class Dog
Dog.java:35: error: non-static variable this cannot be referenced from a static context
Dog spike = new Dog(5);
^
Dog.java:36: error: cannot find symbol
spike.bark();
^
symbol: method bark()
location: variable spike of type Dog.Dog
Dog.java:37: error: cannot find symbol
spike.run(40);
^
symbol: method run(int)
location: variable spike of type Dog.Dog
Dog.java:38: error: cannot find symbol
int spikeAge = spike.getAge();
^
symbol: method getAge()
location: variable spike of type Dog.Dog
7 errors


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);
    spike.checkStatus();

	}

}


#2

dont need to create extra class to extend

class Dog { //remove it
  
  class Dog extends Animal {

you can use same class

  class Dog extends Animal {
  
  int age;

#3

It still says that the objective of "Within the main method of the Dog class, call the checkStatus method on the spike object" is wrong


#4

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