Can we create an instance of an interface in Java? [duplicate]

This question already has an answer here:

Is it possible to create an instance of an interface in Java?

Somewhere I have read that using inner anonymous class we can do it as shown below:

interface Test  
{  
    public void wish();  
}  
class Main  
{  
    public static void main(String[] args)  
    {  
        Test t=new Test()  
        {  
            public void wish()  
            {  
                System.out.println("output: hello how r u");  
            }  
        };  
    t.wish();  
    }  
}    

cmd> javac Main.java  
cmd> java Main  
output: hello how r u  

Is it correct here?

72
задан informatik01 26 October 2013 в 21:32
поделиться