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 string substring?
Can we have multiple classes in single file ?
How do you use nextline in java?
aabccdee Find the used alphabets as abcde ?
Is array dynamic in java?
Why does java doesnt suuport unsigned values?
Marker interface means , interface which has no methods.Then what is the necessity of its usage.I read "it tells the compiler that it should be treated differently ". "It is used to store state of an object". But still am not clear.Please explain clearly.
What is the use of singleton?
What is an abstract class and what is it’s purpose?
What is object cloning in Java?
0 Answers SwanSoft Technologies,
what is the difference b/w static and final methods?
Can an integer be null java?