12/13 inheritance


#1




Dog.java:12: error: class, interface, or enum expected
public void bark(){
^
Dog.java:14: error: class, interface, or enum expected
}
^
Dog.java:16: error: class, interface, or enum expected
public void run(int feet){
^
Dog.java:19: error: class, interface, or enum expected
}
^
Dog.java:21: error: class, interface, or enum expected
public int getAge(){
^
Dog.java:23: error: class, interface, or enum expected
}
^
Dog.java:26: error: class, interface, or enum expected
public static void main(String[] args) {
^
Dog.java:31: error: class, interface, or enum expected
spike.bark();
^
Dog.java:33: error: class, interface, or enum expected
spike.run(1000);
^
Dog.java:35: error: class, interface, or enum expected
int spikeAge = spike.getAge();
^
Dog.java:37: error: class, interface, or enum expected
System.out.println(spikeAge);
^
Dog.java:39: error: class, interface, or enum expected
spike.checkStatus();
^
Dog.java:40: error: class, interface, or enum expected
}
^
13 errors


public 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(2);
    
    spike.bark();
    
    spike.run(1000);
    
    int spikeAge = spike.getAge();
    
    System.out.println(spikeAge);
    
    spike.checkStatus();
	}

}


#2

Your curly braces were messed up. you closed the class early on line

Any code after the last curly brace is not recognized by the compiler.
That said, now you have a bunch of methods that aren't in a class.

-cheers, PythonMaster


What's wrong in my code 12/13 oop
#3

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