Answer the question
In order to leave comments, you need to log in
Anonymous class in Java?
Hello. I'm new to JAVA and currently learning about anonymous classes, I wrote a simple code for an anonymous class, but it throws an error. Please help, why can't I run the show() method??
The code:
public class MyClass {
public static void main(String args[]) {
Employee t = new Employee() {
public void show() {
System.out.println("Some Text");
}
};
t.show();
}
}
class Employee {
public String name = "Test";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question