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 the difference between declaration and definition in java?
What things should be kept in mind while creating your own exceptions in java?
What is set and get methods in java?
How to convert string to char and vice versa?
What do you mean by hashing?
What is the difference between a checked and an unchecked exception?
What is ‘has a’’ relationship in java?
What is thread safe singleton?
Is the empty set a singleton?
Why enumeration is faster than iterator?
Is string is a data type?
What is string data type?
How do you end a program?
Is assembly language a low level language?
What is a protected method?