did interface can implementation method ? i know its not
possible but my interviewer said its possible ..but how..?
any one have idea ???
Answer Posted / arpan mondal
Yes, an interface can if it has a class in it.
Here is the code what i am trying to say...
// MethodImplementedInterface.java
/**
*@author Arpan Mondal(www.arpanmondal.tk)
*/
interface A {
public class B {
B() {
display();
}
public void display() {
System.out.println("This is the
method in the interface.");
}
}
}
class C implements A {
B objB = new B();
void display() {
System.out.println("This is the method in
the class.");
}
}
public class MethodImplementedInterface {
public static void main(String[] args) {
C objC = new C();
objC.display();
}
}
The output of the above code is here...
This is the method in the interface.
This is the method in the class.
| Is This Answer Correct ? | 10 Yes | 0 No |
Post New Answer View All Answers
What is string and its types?
What is indexof in java?
What about member inner classes?
What is a string token?
What are the types of sockets in java?
Difference between string, string builder, and string buffer?
Why do we use predicate in java?
What is the purpose of the runtime class in java programming?
Convert Binary tree to linked list.
Can a vector contain heterogenous objects?
Can java hashmap have duplicate keys?
How do you sing an Applet ?
How do you create a null object?
I want to re-reach and use an object once it has been garbage collected. How it's possible?
Is array an object in java?