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


Please Help Members By Posting Answers For Below Questions

What are different type of exceptions in java?

544


Explain about instanceof operator in java?

605


Can we use catch statement for checked exceptions?

508


What is the buffer limit?

555


How do you create a null object?

506






What is an array in java?

636


What are class members by default?

656


What is Major and importance difference between for and foreach loop ?

570


What is difference between wait and notify in java?

541


How do I remove a character from a string in java?

497


What is the final keyword in java?

549


What do you mean by platform independence of Java?

532


Difference between keyword and identifier.

589


What is the difference between error and an exception?

567


What is navigable map in java?

516