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

Hi Friends, can u give me Real Time example for interface and abstract class.(With Banking Example)

4 Answers  


Howmany number of objects we can store in an ArrayList. Is there any limit?

7 Answers   TCS,


What is the file type?

0 Answers  


Why string is immutable with example?

0 Answers  


Can we override private method in java?

0 Answers  






To obtain design information about an object, which class in used?

1 Answers  


Write a method to check if input string is palindrome?

0 Answers  


do I need to use synchronized on setvalue(int)? : Java thread

0 Answers  


What is meant by class and object in java?

0 Answers  


How to override a equals() method and what is the use?

1 Answers  


Consider that class classA, abstract class classB, and final classC have been defined.Which one of the following is correct? 1. classA extends classC implements classB 2. class A extends classB, classC 3. classA extends classB 4. classB implements classC

2 Answers  


Can we serialize singleton class?

0 Answers  


Categories