Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Posts
    277
    Thanks
    10
    Thanked 1 Time in 1 Post

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Oct 2010
    Posts
    277
    Thanks
    10
    Thanked 1 Time in 1 Post
    OH! I knew it was something small. I feel dumb right now lol.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •