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
How do you check if two strings are equal in java?
What do you understand by Header linked List?
Can you override private or static method in java?
What is the difference between a factory and abstract factory pattern?
What is json parser in java?
Write a program to find the whether a number is an Armstrong number or not?
What is a text string?
How garbage collection is done in java?
List some oops concepts in java?
Outline the major features of java.
How do I write a self declaration?
What is a website container?
What is the mapping mechanism used by java to identify IDL language?
What are wrapped classes in java programming?
What is the difference between heap and stack memory?