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.printl n("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.") ;
}
}
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(
void Eat(){System.out.println("
void Weight(){System.out.printl
}
--------------------------
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.