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 are order of precedence and associativity, and how are they used?
What is the default modifier in Interface?
How do you create a first line indent?
Write an algorithm program in java for the following question.. In a VLSI design techniques,they used rectangles to design circuits. EVery rectangle is to be placed according to x,y coordinates. Check whether or not two rectangles overlap each other. Here overlapping of rectangles is acceptable, if 1) one rectangle intersect with other. 2) one rectangle fully covers other. The time of algorithm should not exceed o(n logn).
Can I learn java in 3 months?
What is equals method in java?
What are the five major types of reference sources?
What is string and its types?
How to calculate the length of a singly linked list in java?
What is Major and importance difference between for and foreach loop ?
If I will write String s=new String("XYZ"); String s1=new String("XYZ"); if(s.equals(s1)){ sop("True"); } else{ sop("False"); } This program will give me "True". But When I am creating my own class suppose class Employee{ public Employee(String name); } Employee e= new Employee("XYZ"); Employee e1 = neew Employee("XYZ"); if(e.equals(e1)){ sop("True"); } else{ sop("False"); } Then it will give the output as "False". Can I know what is happening internally?
What is the biggest integer?