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

Why java is platform independent? Explain.

0 Answers  


Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.

0 Answers  


What is data and its types?

0 Answers  


What is logical variable?

0 Answers  


Which is faster set or list in java?

0 Answers  


What is a top level class in java?

0 Answers  


What is the destroy method?

0 Answers  


What is Yield() method when we r using this ? tell exactly

2 Answers  


What is the maximum size of hashmap in java?

0 Answers  


How do you define a method?

0 Answers  


How to sort the elements in HashMap

3 Answers   Ness Technologies,


Explain the transient field modifier?

0 Answers  


Categories