we cannot create an object of interface but we can create
a variable of it



we cannot create an object of interface but we can create a variable of it ..

Answer / 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

More Core Java Interview Questions

What is a constructor, constructor overloading in java?

0 Answers  


If a variable is declared as private, where may the variable be accessed?

0 Answers  


What is string builder in java?

0 Answers  


What are the default and parameterized constructors?

0 Answers  


What is flush buffer?

0 Answers  


what is a thread?

13 Answers   IBM, SunGard,


What are different types of control structures?

0 Answers  


Why is String immutable?

0 Answers   Atos Origin,


Can we create our own daemon thread?

0 Answers  


What is a ternary operator in java?

0 Answers  


Tell me the Importent classes in net package?

0 Answers  


What is the collections api?

0 Answers  


Categories