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
Explain the difference between the public, private, final, protected, and default modifiers?
Are maps ordered java?
what are Hostile Applets?
What is string args [] in java?
What is nested class?
Is singleton set an interval?
What is type inference in java8?
what is an objects lock and which objects have locks? : Java thread
What is byte value?
Is this valid in java ? Can we instantiate interface in java?
how to create multithreaded program? : Java thread
Is null a value?
Explain the importance of finally over return statement?
Can we write a class without main method in java?
Can we override private method in java?