Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

What's wrong with this code ?

  Asked By: Vivek    Date: Oct 19    Category: Java    Views: 740
  

What's wrong with this code ?

----------Animal.java----------
public class Animal
{
private String type;

public Animal( String atype)
{
type= atype;
}

public void show()
{
System.out.println("This is a " + type);
}
}
----------------dog.java----------
public class Dog extends Animal
{
private String name;
private String breed;

public Dog (String name,String breed);
{
super("Dog");
name= name;
breed= breed;
}
public Dog(String name)
{
super("Dog");
name = name;
breed ="unknown";
}

}
------------------TestAnimal---------------

public class TestAnimal
{
public static void main(String args[])
{
Dog a = new Dog("Lassie");
Dog a1 = new Dog("Fido","Chihuahua");
a.show();
a1.show();
}
}
------------------------------

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Dan Romero     Answered On: Oct 19

should be this.name

using just name  is ambigous

 
Answer #2    Answered By: Clint Garcia     Answered On: Oct 19

Remove the semicolon(;) in the following line
public Dog (String name,String breed);<------
It worked fine with me

 
Answer #3    Answered By: Wilfred Young     Answered On: Oct 19

There is a semicolon at the end of the statement where
you are defining the Dog(String name, String breed)
constructor. Remove the semicolon and the code  works
fine.

 
Didn't find what you were looking for? Find more on What's wrong with this code ? Or get search suggestion and latest updates.




Tagged: