Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-31-2012, 05:48 PM   PM User | #1
andynov123
Regular Coder

 
Join Date: Oct 2010
Posts: 246
Thanks: 8
Thanked 1 Time in 1 Post
andynov123 is an unknown quantity at this point
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
andynov123 is offline   Reply With Quote
Old 10-31-2012, 06:34 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,661
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-01-2012, 03:10 PM   PM User | #3
andynov123
Regular Coder

 
Join Date: Oct 2010
Posts: 246
Thanks: 8
Thanked 1 Time in 1 Post
andynov123 is an unknown quantity at this point
OH! I knew it was something small. I feel dumb right now lol.
andynov123 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:52 AM.


Advertisement
Log in to turn off these ads.