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 are the advantages of java over C++?

941


What is ph and buffers?

750


what is the messsage u r going to get from an objectoriented programing?

1902


What are adapter classes?

803


What is static block?

811


What is singleton pattern?

805


Is nan false?

736


Can there be an abstract method without an abstract class?

738


What are benefits of java?

818


What is subsequence of a string?

854


What is a ternary operator in java?

771


how would you implement a thread pool? : Java thread

705


What are the different types of data structures in java?

752


What is string syntax?

828


What value is a variable of the string type automatically initialized?

843