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 is console based application in java?
Can a static method be overridden in java?
What is the difference between abstract classes and interfaces?
What are the differences between string and stringbuffer?
Why are the methods of the math class static?
What are the advantages of unicode?
What is a boolean structure?
What is difference between string and new string?
What is use of super keyword?
Which class cannot be a subclass in java?
In a container there are 5 components. I want to display all the component names, how will you do that?
What is default switch case? Give example.
Explain different forms of polymorphism?
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.
Is java util list serializable?