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 are selection structures?
How to print an arraylist in java?
What is autoboxing in java?
How many java versions are there?
Write a program to find maximum and minimum number in array?
What is mutable object and immutable object?
Is null a string?
What is run time allocation?
Explain method overloading?
how to write a server program and sending the mails to the server using smtp protocol please help me
What are drawbacks of singleton class?
Is zero a positive integer?
How do you start a thread?
What is difference between printf and scanf?
What is == and === in javascript?