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
Which is better ascii or unicode?
How many classes can any class inherit java?
What is a generic type?
What is a protected class in java?
Where is java located?
What will happen when using pass by reference in java?
What is method in java with example?
Why main method is called first in java?
What are the basic interfaces of java collections framework?
What is the purpose of the enableevents() method?
Why method overriding is used?
Give example to differentiate between call by value and call by reference.
What are class types in java?
Is 0 true or is 1 true?
What ide should I use for java?