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


Please Help Members By Posting Answers For Below Questions

Explain the difference between arraylist and linkedlist in java?

704


What are the restriction imposed on a static method or a static block of code?

815


What are the types of inner classes (non-static nested class) used in java?

805


What are abstract methods in java?

880


What is the difference between final, finally and finalize() in java?

785


When is update method called?

886


What is java abstraction with example?

728


Which is easier .net or java?

846


Can java list contain duplicates?

792


Is string a wrapper class?

747


Are maps ordered java?

706


If system.exit (0); is written at the end of the try block, will the finally block still execute?

833


Is null an object java?

745


What is the difference between jfc & wfc?

800


What is replaceall in java?

769