Link to home
Start Free TrialLog in
Avatar of meow00
meow00

asked on

subclass

Hi Experts,

    I already declared name and age in the superclass, why that I can't use them in the subclass line 01 & line 02 ?

   Thanks !!!

--------------------
public abstract class MyAnimal {
   
    /** Creates a new instance of MyAnimal */
    public MyAnimal() {
    }
    String name ;
    int age ;
    void Talk(){System.out.println("Each animal has its own language."); }
    void Eat(){System.out.println("Each animal needs food.") ;}
    void Weight(){System.out.println("I don't like fat animals !") ;}
}
----------------------------------------
public class MyDog extends MyAnimal{
   
    name = new String("Doggy") ;            // line 01
    age = new int(5) ;                              // line 02
    /** Creates a new instance of MyDog */
    public MyDog() {
        System.out.println("I am a dog. My name is Doggy !") ;
    }
   
    void Talk(){
        System.out.println("    Woof ! I talk as Woof Woof !") ;
    }
   
    void Eat(){
        System.out.println("    Woof ! I like to eat bones.") ;
    }
   
    void Weight(){
        System.out.println("    Woof ! I weight 60 pounds.") ;
    }
}
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial