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
Can we declare an array without size in java?
What is a singleton puppy?
How can you make a class serializable in java?
What is serial version uid and its importance in java?
What is a native method in java programming?
How do you square a number?
Explain the difference between abstraction and encapsulation.
Is char a data type in java?
Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?
What happens if an exception is throws from an object's destructor?
What is the purpose of using bufferedinputstream and bufferedoutputstream classes?
Can a class extend more than one class?
Convert Binary tree to linked list.
What is java virtual machine? Explain
Why is inheritance used in java?