CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   What is wrong with this code? (http://www.codingforums.com/showthread.php?t=280229)

andynov123 10-31-2012 05:48 PM

What is wrong with this code?
 
public class Dog extends Mammals {

public Dog(String name, String type) {
super(name, type);

}
public String sound{
System.out.println("Hello");

}
}



Syntax error. Insert ";" to complete FieldDeclaration.

The error appears under "sound" which is underlined with the error

Fou-Lu 10-31-2012 06:34 PM

Is sound supposed to be a method? You're missing the () if it is.
Otherwise, Java thinks its a property called sound which needs to be semi-colon terminated. Java will accept a class level static block such as this:
PHP Code:

public String sound "";

{
    
System.out.println("hello");


Although I doubt that is the intent here.

andynov123 11-01-2012 03:10 PM

OH! I knew it was something small. I feel dumb right now lol.


All times are GMT +1. The time now is 09:59 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.