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 an 8 bit word?
Name the methods in mouse listeners ?
How we can declare a static variable?
how you will prevent method overriding?
What is the difference between stringbuffer and stringbuilder class?
Scenario: There are 1 to 100 numbers. Each number should be keep in the each column like from A column to Z column ie 1 to 26. From 27 to 52 should be in 2nd row in the excel sheet. This has to be continue till 100. How do you write Java program and what are various methods.
Explain access specifiers?
0 Answers Thomson Reuters, Virtusa,
What is the most important feature of java? What is an interface?
What is java jit compilers?
What's the purpose of static methods and static variables?
Find the value of a specified element of the array arr[i] where 0 <= i <= n-1
Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain