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

Can we declare an array without size in java?

516


What is a singleton puppy?

524


How can you make a class serializable in java?

563


What is serial version uid and its importance in java?

594


What is a native method in java programming?

523






How do you square a number?

576


Explain the difference between abstraction and encapsulation.

535


Is char a data type in java?

537


Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?

651


What happens if an exception is throws from an object's destructor?

579


What is the purpose of using bufferedinputstream and bufferedoutputstream classes?

546


Can a class extend more than one class?

605


Convert Binary tree to linked list.

582


What is java virtual machine? Explain

564


Why is inheritance used in java?

599