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 does opcode mean?
What does the @override annotation do?
What is the primitive type byte?
What is java reflection api?
how to handle exceptions in ejb?
What methodology can be employed to locate substrings inside a string?
What are the names of Component subclasses that support painting?
Which package is used for pattern matching with regular expressions?
Can string be considered as a keyword?
Which arithmetic operations can result in the throwing of an arithmeticexception?
Why is it called buffering?
what is comparable and comparator interface?