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
How do you remove an object from an arraylist in java?
What do you understand by looping in java? Explain the different types of loops.
Which is better list or arraylist in java?
Can we override constructor?
What is a qualifier in a sentence?
What is map and hashmap in java?
Can we serialize singleton class?
Is list thread safe in java?
Is it safe to install java on my computer?
How do I stop concurrentmodificationexception?
What is map in java?
Why you should not use singleton?
Can we cast any other type to boolean type with type casting?
What does function identity () do?
What is the difference between post and put?