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
Whats the difference between notify() and notifyall()?
What’s the difference between applets and standalone program?
What is oops in java?
What is the use of hashmap in java?
What is difference between float and double?
Is zero a natural number?
How to create com object in Java?
What are predicates in java 8?
Similarity and difference between static block and static method ?
What is singletonlist in java?
how to create multithreaded program? Explain different ways of using thread? : Java thread
What is import java util arraylist?
When a byte datatype is used?
What is style and indentation?
What is the difference between heap and stack memory?