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 is the main advantage of passing argument by reference?

505


What is the dot operator?

572


Is integer passed by reference in java?

571


What classes of exceptions may be thrown by a throw statement?

531


What is final access modifier in java?

594






Why Java is not pure Object Oriented language?

648


How is hashset defined in java?

519


What is a numeric format?

571


What is stack example?

549


What is garbage collection? Can it be forced to run?

543


Is map sorted in java?

570


What does this () mean in constructor chaining concept?

564


Is null a string?

558


What is api data?

544


What is bufferedreader in java?

580