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
Differentiate between static and non-static methods in java.
what is meant by HQL?
Can a class be declared as protected?
What is meant by memory leak?
Why we used break and continue statement in java?
Why hashset is used in java?
What does it mean to flush a file?
When should we create our own custom exception classes?
What kind of variables a class can consist of?
What are the basics of core java?
How list contains works in java?
Is cout buffered?
What is a map? What are the implementations of map?
What does a method signature consist of?
What is difference between overloading and overriding in java?