I have this code where ChildClass implements an interface Demo . the same method signature is used in SuperClass.
This code compiles fine.
Isn't it the breach in the contract of implementing an interface?
even though ChildClass 'has' doNothing() method but it doesn't implement it for the sake of Interface Contract.
what exactly is happening here.
Doesn't matter. To implement an interface, a class needs to 'have' all instance methods declared by the interface, with matching signatures and compatible return types and visibility. How it got them is of no consequence.
The "contract" means that you can call the methods defined in the interface - not that each class has to explicitly implement them. You can quite clearly call doNothing on an instance of ChildClass, so the contract is fulfilled.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
well thats correct.
The implementing class should "have" all the methods declared in an interface . its not written any where that it should 'implement' all the methods.
Comparator interface is an example of the same.
Thanks for the clarification
java is best because i can even drink it.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database