I'm newbie to Java. I would like to ask different between the following interface examples?
public interface MyInterface { public void doSomething(); } like this
public class MyClass implements MyInterface { public void doSomething {....} } and this
public class MyClass implements MyInterface { protected MyInterface myInterface; public MyClass (MyInterface myInterface) { this.myInterface = myInterface; } public void doSomething () { myInterface.doSomething(); } }
MyInterfaceto pass to your constrcutor? What would any benefit be?