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

List any five features of java?

803


What are the three parts of a lambda expression? What is the type of lambda expression?

825


How do you decide when to use arraylist and linkedlist?

758


What is singleton service?

726


What is a package in java? List down various advantages of packages.

996


Can you pass by reference in java?

746


What are the four corner stones of oop?

800


What does substring mean?

720


What is the difference between the font and fontmetrics classes in java programming?

721


Why main() method is public, static and void in java ?

854


What is mnemonic in assembly language?

829


What is sizeof () operator?

757


What is a numeric digit?

795


Name few java 8 annotations ?

804


Explain exception chaining in java?

851