can you create interface instance ?

Answer Posted / nishant

hi Uday,what you've done is, created an annonymous inner
class which is the implementer class of the interface.Here
the refernce variable is of the interface but it is
referencing to the newly created annonymous inner class
instance.
Here the instanceof operator returns true because
annonymous inner class is the implementer of interface and
instanceof always returns true with the same class or its
super class(try using instanceof with Object class, it will
always return true,may the object be of any class).

Is This Answer Correct ?    14 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do heavy weight components mean in java programming?

525


Tell me the latest versions in java related areas?

585


What is the default access specifier for variables and methods of a class?

568


Is empty set an element of empty set?

605


How many JVMs can run on a single machine and what is the Just-In-Time(JIT) compiler?

577






Explain runtime exceptions?

745


Can I override protected method in java?

596


what do you mean by classloader in java?

570


What is flag in python?

555


How do you sort arrays in java?

526


How define set in java?

514


How you can force the garbage collection?

540


What is the use of isempty in java?

537


What is meant by method?

577


Does string is thread-safe in java?

593