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 the list interface?

840


What are parsing rules?

725


How strings are created in java?

793


What are scriptlets?

826


List types of storage classes in java?

825


What about static nested classes in java?

824


How do you use compareto?

713


Explain the difference between protected and default access.

740


What is the implementation of destroy method in java. Is it native or java code?

727


How to calculate the length of a singly linked list in java?

776


What is keyword in oop?

742


What's the purpose of using break in each case of switch statement?

756


Why is singleton class used?

772


Can we create object of static class?

750


What is unicode used for?

816