we cannot create an object of interface but we can create
a variable of it
Answer Posted / mahesh
For creating an object, interface does not contain the body of its abstract methods. Hence compiler does not have enough data for creating an object out of it.
On the other hand you can create a variable of that interface with any other class implementing that interface.
E.g. A is an interface and B is a class implementing A.
Now if you create
A obj = new A();
This statement wont give an implementation of methods inside A.
But,
class B implements A{
}
A obj = new B();
Here class B will be defining all the abstract methods inside interface A.
Hence it is not possible to create an object of interface but you can create a variable of it.
Is This Answer Correct ? | 9 Yes | 1 No |
Post New Answer View All Answers
What are different type of exceptions in java?
Explain about instanceof operator in java?
Can we use catch statement for checked exceptions?
What is the buffer limit?
How do you create a null object?
What is an array in java?
What are class members by default?
What is Major and importance difference between for and foreach loop ?
What is difference between wait and notify in java?
How do I remove a character from a string in java?
What is the final keyword in java?
What do you mean by platform independence of Java?
Difference between keyword and identifier.
What is the difference between error and an exception?
What is navigable map in java?