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 hashmap is used in java?

0 Answers  


How a class can implement an interface?

5 Answers   SysArc,


What is JVM ?

4 Answers   Phantom Technologies, TCS,


What is the difference between math floor and math round?

0 Answers  


why to use transient variables when static variables can be used for Serialization

4 Answers  






What do you know about the garbage collector?

0 Answers  


Can singleton class be inherited in java?

0 Answers  


Why there is no call by reference in java?

0 Answers  


Tell me the difference between an applet and a Japplet?

1 Answers  


I declared main() method as private. But it still running and displaying the output. Please Answer it . Code Snippet as Below: import java.io.*; class over { private static void main(String[] args) { int high = Integer.MAX_VALUE; int overflow = high + 1; int low = Integer.MIN_VALUE; int underflow = low - 1; System.out.println(high + "\n" +overflow +"\n"+ low +"\n"+underflow); //System.out.println(overflow); //System.out.println(low); //System.out.println(underflow); } }

4 Answers   Cap Gemini,


java can provide security ,how can provide?

8 Answers   Aspire, BNP Paribas, Genpact, IBM,


Who developed JScript language?

3 Answers  


Categories