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
Is there any difference between synchronized methods and synchronized statements?
Can we use both this () and super () in a constructor?
Is final static java?
What do you know about java?
Make a data structure and implement an algorithm to print all the files in a directory. (The root directory can have sub-directories too.)
Why string objects are immutable in java?
What is used of static keyword in java?
What is difference between iterator access and index access?
what is mena by object block any what is the use of that
When can you say a graph to be a tree?
Explain different ways of creating a thread?
What are synchronized methods and synchronized statements in java programming?
Difference between object instantiation and construction ?
What is fundamental datatype?
what is daemon thread and which method is used to create the daemon thread? : Java thread