A
A
Alexander Kudryashov2016-11-06 15:09:29
Java
Alexander Kudryashov, 2016-11-06 15:09:29

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

1 answer(s)
A
al_gon, 2016-11-06
@Spacegrey

public class MyClass {
   public static void main(String args[]) {
        Employee t = new Employee() {
          public void show() {
            System.out.println("Some Text");
          }
        };
        t.show();
      }
    }
    interface Employee {
      void show();
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question