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
How will you invoke any external process in java?
Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.
What do you understand by garbage collection in Java? Can it be forced to run?
What are the ways to instantiate the class class?
What is == mean?
Explain about the main() method in java?
What are keywords in java?
Explain inheritance in java?
What are exceptions
Why do we need variables?
What is run time allocation?
What is hash code collision?
What are the four corner stones of oop?
Can an interface extend another interface?
What is multiple inheritance? Is it supported by java?