Solved

subclass

Posted on 2004-09-12
1
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

762 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