English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have three java files , i am pasting them here. Please show me the errors. Compilation error in Cat.java
File 1 : Dog.java
public class Dog extends Animal {
public String noise() { return "back"; }
}
File 2 : Cat.java
public class Cat extends Animal {
public String noise() {
return "meow";
)
}

File 3:AnimalTest.java
public class AnimalTest {
public static void main(String[] args)
{
Animal animal = new Dog();
//Cat cat = (Cat)animal;
Cat cat = new Cat();
System.out.println(cat.noise());
}
}

Output :
D:\>javac AnimalTest.java
.\Cat.java:4: illegal start of expression
)
^
.\Cat.java:5: ';' expected
}
^
.\Cat.java:5: '}' expected
}
^
3 errors

Please help me. Not a homework.

File 2: Cat.java

2006-08-15 18:07:48 · 4 answers · asked by K Ban 2 in Computers & Internet Programming & Design

My Dear Nikihl nobody can terminate a class in java with semicolon.

2006-08-15 18:17:36 · update #1

Leave spelling mistake. Find the problem

2006-08-15 18:18:21 · update #2

Manju thank you. The editor was so, small i cannot differentiate between { and (.
Thanks. Your is Best Answer.

2006-08-15 18:21:43 · update #3

4 answers

check out ur program cat.java
in the 4th line u used ')' instead of '}'
that is wht is causing errors...
i think this will clear those...

2006-08-15 18:18:21 · answer #1 · answered by Anonymous · 2 0

In line 4, Cat.java, replace the ")" with a "}".

New code looks like:

File 2 : Cat.java
public class Cat extends Animal {
public String noise() {
return "meow";
}
}

2006-08-15 19:49:14 · answer #2 · answered by Neilesh 1 · 0 0

I think you also erred here::

public String noise() { return "back"; }

Shouldn't it be...

public String noise() { return "bark"; }

?

2006-08-15 18:16:56 · answer #3 · answered by vinny_the_hack 5 · 0 0

class declaration shuold be terminated by semi colon
class A
{
...
}; <--//Note this

2006-08-15 18:12:22 · answer #4 · answered by Nikhil G 3 · 0 0

fedest.com, questions and answers