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 daemon Threads in java?
Can you create an object of an abstract class?
How can we access some class in another class in java?
What is thread count in java?
What is the method overriding?
What is the purpose of void class?
What is multithreading in java?
What is class forname?
What is a newline character in java?
Why is a string immutable?
What do you mean Abstraction in java?
how to write a server program and sending the mails to the server using smtp protocol please help me
How to store image in arraylist in java?
Which is faster set or list in java?
Why is java called java?