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: 697

What's wrong with this code ?

public class Animal
private String type;

public Animal( String atype)
type= atype;

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

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


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



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

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