can we create a instance for intwerface?
Answers were Sorted based on User's Feedback
Answer / subhash
No.We cannot create instance for interface.But we can
create reference to an interface.We can implement the
interface by creating sub class(implementation class) and
creat instance to the sub class, then you can create
reference to the interface by assigning instance of sub
class to the interface reference variable.
| Is This Answer Correct ? | 8 Yes | 0 No |
Answer / uma
no.Interface is similar to class but they lack instance
variable, their methods are declared with out any body.
Interfaces are designed to support dynamic method
resolution at run time. All methods in interface are
implicitly
abstract, even if the abstract modifier is omitted.
Interface methods have no implementation;
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / amit kumar gautam
Though it is correct that interfaces are basically used for
obtaining the dynamic resoulution of the Method and they
usually can not be instantiated but it is also possible to
instantiate the same in case of anonymous classes and it
works fine.......
class Amit
{
void addCode()
{
Runnable rr=new Runnable()
{
public void run()
{
System.out.print("This is Amit")
}
};
Thread tt=new Thread(rr);
tt.start();
}
}
class Check
{
static public void main(String[]amit)
{
new Amit().addCode();
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the use of parse function in java?
When we give defination of interface method in the class why method must be public???
What is the middleware?
Can you explain inner class.
How are multiple inheritances done in Java?
Is java owned by oracle?
What are heterogeneous objects?
Package1 and Package2 both have a method name lets say "methodA" with different implementation. When I import both the packages in a java class how can I use both the methods?
We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending to thread class and overriding run method. Among these two which one is better and why? Please explain me in detail.
Difference between static binding and dynamic binding?
What is tostring () method?
What is the difference between Grid and Gridbaglayout?