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
What is the list interface?
What are parsing rules?
How strings are created in java?
What are scriptlets?
List types of storage classes in java?
What about static nested classes in java?
How do you use compareto?
Explain the difference between protected and default access.
What is the implementation of destroy method in java. Is it native or java code?
How to calculate the length of a singly linked list in java?
What is keyword in oop?
What's the purpose of using break in each case of switch statement?
Why is singleton class used?
Can we create object of static class?
What is unicode used for?