can you create interface instance ?

Answer Posted / zafar

No, you cannot create an instance of an interface. An
interface has no implementation - a class that implements
the interface specifies the implementation.

However, you can ofcourse have a reference variable of an
interface type that points to an instance of a class that
implements the interface. For example:

// List is an interface, ArrayList implements interface List
List data = new ArrayList();


It's good practice to program like this - program to an
interface, not an implementation. If you want to know more
about that design principle, see, for example:
[url=http://www.artima.com/lejava/articles/designprinciples.
html]Design Principles from Design Patterns[/url]

Is This Answer Correct ?    13 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is default switch case? Give example.

576


State the merge-sort principle and its time complexity.

573


Can we have multiple public classes in a java source file?

558


What is string length in java?

493


What are loops in java? What are three types of loops?

551






What do you understand by java?

563


What is gc()?

581


What is ++ a in java?

570


What are nested classes in java?

606


How to split arraylist elements in java?

600


How do you create a sop?

529


What access modifiers can be used for variables?

586


Can you explain the private protected field modifier?

571


Explain about interrupt() method of thread class ?

666


FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?

2637