Bummer! You must be logged in to access this page.

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

This simple JAVA code is not working?

This is my code:

class Human { public void eat(){ System.out.println("Human is eating"); }

}

class Boy extends Human {

public void eat() {
    System.out.println("Boy is eating");
}

}

public static void main (String[] args){ Boy obj = new Boy(); obj.eat(); }

IDE - Intellj or Eclipse

Error - In line 13 and 18, "Class or interface expected" . Kindly help me.

1 Answer

Your closing curly brace for your Boy class didn't enclose the class itself, otherwise, your code looks fine:

class Human {
    public void eat() {
        System.out.println("Human is eating");
    }
} //closing curly brace for the Human class

class Boy extends Human {
    public static void main(String[] args) {
        Boy b = new Boy();
        b.eat();
    }

    public void eat() {
        System.out.println("Boy is eating");
    }
} //closing curly brace for the Boy class