Java – Method name collision in interface implementation

No, there is no way to implement the same method in two different ways in one class in Java. That can lead to many confusing situations, which is why Java has disallowed it. interface ISomething { void doSomething(); } interface ISomething2 { void doSomething(); } class Impl implements ISomething, ISomething2 { void doSomething() {} // … Read more

Difference between Inheritance and Composition

They are absolutely different. Inheritance is an “is-a” relationship. Composition is a “has-a”. You do composition by having an instance of another class C as a field of your class, instead of extending C. A good example where composition would’ve been a lot better than inheritance is java.util.Stack, which currently extends java.util.Vector. This is now … Read more

tech