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
describe synchronization in respect to multithreading? : Java thread
What does java ide mean?
Compare overloading and overriding?
In how many ways we can do synchronization in java?
Is java a super set of javascript?
What are the types of methodology?
What are the 6 mandatory procedures for iso 9001?
Is the empty set a singleton?
Can a class be a super class and a sub-class at the same time? Give example.
What is jvm? Why is java called the platform independent programming language?
What is a variable declaration?
What is the difference between interface & abstract class?
What are the limitations of procedural programming approach?
Why string is called as immutable?
What are the ways to instantiate the class class?