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
State the main difference between c++ and java?
What is the purpose of the file class in java programming?
Explain a situation where finally block will not be executed?
When is an object subject to garbage collection?
Why is core java important?
Can interface be private in java?
Why string objects are immutable in java?
Explain about join() method?
What is return used for in java?
Which is bigger double or float?
What is use of map in java?
What is the scope or life time of instance variables?
Why singleton pattern is better than creating singleton class with static instance?
Is empty list java?
What is the difference between compile-time polymorphism and runtime polymorphism?