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
Is main is a keyword?
How does sublist works in java?
We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.
What are different types of inner classes ?
Is sizeof a preprocessor?
What is a text string?
Is 0 true or false in java?
What is mutable object and immutable object?
What is meant by method overriding?
What is logical variable?
What is double data type?
1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?
Which way a developer should use for creating thread, i.e. Sub classing thread or implementing runnable.
What is constant in programming?
Lowest Common ancestor in a Binary Search Tree and Binary Tree.