Home » questions » Typical problem in java program ?

Typical problem in java program ?

2006-08-15 22:07:48, Category: Programming & Design
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 My Dear Nikihl nobody can terminate a class in java with semicolon. Leave spelling mistake. Find the problem Manju thank you. The editor was so, small i cannot differentiate between { and (. Thanks. Your is Best Answer.

Answers

  1. Neelesh K

    On 2006-08-15 23:49:14


    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"; } }
  2. Nikhil G

    On 2006-08-15 22:12:22


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

    On 2006-08-15 22:18:21


    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...
  4. vinny_the_hack

    On 2006-08-15 22:16:56


    I think you also erred here:: public String noise() { return "back"; } Shouldn't it be... public String noise() { return "bark"; } ?