Can a Java interface exist that would be implemented by a method rather than by a class?
Your problem statement is not clear.
Are you looking for an example where a class does not implement an interface and a method in that class provides implementation?
One example:
executor.submit(new Runnable(){
public void run(){
System.out.println("Thread Name in Runnable:"+
Thread.currentThread().getName());
}
});
In this example,
My main class does not explicitly quote that it implements Runnable
interface but it simply implemented run() method of Runnable interface.
EDIT:
If your professor is talking about new features of interface in java 8, have a look at this oracle documentation page. With this new feature of default methods, interface have body in methods i.e. they provide default implementation for some methods.
Some important notes on default methods:
Extending Interfaces That Contain Default Methods
When you extend an interface that contains a default method, you can do the following:
- Not mention the default method at all, which lets your extended interface inherit the default method.
- Redeclare the default method, which makes it abstract.
- Redefine the default method, which overrides it.
Especially have a look at "Extending Interfaces That Contain Default Methods
" in oracle documentation page and this article