interface cannot be instantiation

public interface Handler{
public void Hello();

import Handler;
public class OtherParser{
Handler handler;

2) just uses a declaration of the interface, which is different from instiation

public class MyHandler implements Handler{
public void Hellp(){
System.out.println(“my Handler implements”);
Handler handler = new MyHander();


In the case below, Animal is an interface. it uses an anonymous class which is actually a class; that is why it can be instantiated.

Animal animal = new Animal() {
    public void Eat(String name) {
        System.out.printf("Someone ate " + food_name);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s