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

What are selection structures?

527


How to print an arraylist in java?

489


What is autoboxing in java?

595


How many java versions are there?

556


Write a program to find maximum and minimum number in array?

543






What is mutable object and immutable object?

622


Is null a string?

543


What is run time allocation?

568


Explain method overloading?

564


how to write a server program and sending the mails to the server using smtp protocol please help me

1540


What are drawbacks of singleton class?

514


Is zero a positive integer?

522


How do you start a thread?

538


What is difference between printf and scanf?

508


What is == and === in javascript?

551