can you create interface instance ?
Answer Posted / yousif mustafa
I think UDAY is right and he gave the right answer.
We actually couldn't instantiate the interface but we could
instantiate object from class implements this interface and
override all of its methods due to interfaces could only
have abstract methods, but also we can use anonymous inner
class to do that and must override all the abstract method
within creating the object. for ex:
interface Test {
void printA();
void printB();
}
class Inter implements Test {
@Override
void printA() {System.out.println("A from implement");}
void printB() {System.out.println("B from implement");}
}
public class A {
public static void main (String arg[]) {
Test t = new Test() {
void printA() { System.out.println("A form inner"); }
void printB() { System.out.println("B from inner"); }
};
Inter i = new Inter();
t.printA();
i.printA();
t.printB();
i.printB();
}
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
Which collection does not allow duplicates in java?
What is the difference between method overriding and overloading?
What is singleton math?
Which category the java thread do fall in?
What is the purpose of assert keyword used in jdk1.4.x?
What is OOP Language?
Give few difference between constructor and method?
What is java literals?
Tell us something about an iterator.
Is it possible for a yielded thread to get chance for its execution again?
What is the purpose of garbage collection in java?
What is equals method in java?
Can you explain the private protected field modifier?
What is type conversion in java?
Define an applet in java?