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 difference between word and integer?

0 Answers  


What purpose do the keywords final, finally, and finalize fulfill?

0 Answers  


Java support call by reference (pass by reference) ?

1 Answers   HCL,


what is private constructor?what are the uses of writing private constructor in our program?

10 Answers  


What is the static field modifier?

0 Answers  






can any one send me the example program of immutable class?

2 Answers   Arfin, TCS,


What are the rules for naming an array?

0 Answers  


Why java is a platform independent? Explain

0 Answers  


why is multiple inheritance not allowed in java?

7 Answers   Elementus Technologies, Huawei, Infosys,


List some java keywords sun like c, c + + keywords?

0 Answers  


Difference between abtsract & final

1 Answers   Nous,


How do you check if a string contains only numeric digits?

0 Answers  


Categories