Solved

subclass

Posted on 2004-09-12
1
239 Views
Last Modified: 2010-03-31
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.") ;
    }
}
0
Comment
Question by:meow00
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 12040749
because its not in a method

try:

    public MyDog() {
       name = "Doggy" ;  
       age = 5;    
        System.out.println("I am a dog. My name is Doggy !") ;
    }
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now