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 |
Can you override static method in java?
Under what circumstances an object reference be cast to an interface reference?
How many bytes is a unicode character?
Define how destructors are defined in java?
what is meant by Byte code concept in Java?
What is the return type of a program?s main() method?
What is a ?
how we can use debug in myeclipse 6.0 in order solve the problems that exist in our program when there are 900 to 1000 pages in a web application
How do you execute a thread in java?
How do you create a bulleted list?
What is "this" keyword in java? Explain
Write a program to check string is palindrome without using loop?