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

Differentiate between static and non-static methods in java.

577


what is meant by HQL?

649


Can a class be declared as protected?

547


What is meant by memory leak?

546


Why we used break and continue statement in java?

571






Why hashset is used in java?

542


What does it mean to flush a file?

578


When should we create our own custom exception classes?

597


What kind of variables a class can consist of?

643


What are the basics of core java?

558


How list contains works in java?

562


Is cout buffered?

693


What is a map? What are the implementations of map?

582


What does a method signature consist of?

521


What is difference between overloading and overriding in java?

535