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 |
What is the difference between iterator and enumeration ?
Explain the differences between static and dynamic variables?
What is byte value?
How to define a constant variable in Java?
What is the difference between yielding and sleeping in java programming?
What is run time allocation?
Difference between static methods, static variables, and static classes in Java.
What is a java developer salary?
What is high level language in computer?
Why Java is not pure Object Oriented language?
Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?
What is the current version of java?