can you create interface instance ?

Answer Posted / balibalo

to the writer of #29:

what you propose doesn't work because at line where you have t.wish(), Java tries to find the wish() method in the Object class (since t is of type Object). As it doesn't exist in that class, your program fails to compile.
Simple.

Uday version compiles because there is not type unconsistency, but it still is an anonymous class call, hence not a correct answer to the root question (answer being already given: NO, you cannot create an instance of an interface but you can create references of it).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell some latest versions in JAVA related areas?

548


What does || mean in code?

534


What is the final method?

594


Can finally block be used without a catch?

538


What is the difference between logical data independence and physical data independence?

525






List some features of the abstract class.

583


Is empty string in java?

531


What is the purpose of main function in java?

528


What is the purpose of a default constructor?

571


What are the topics in advance java?

503


How strings are created in java?

553


Which is fastest collection in java?

555


What will happen if a thrown exception is not handled?

556


How to handle a web browser resize operation?

535


What is java util?

527