Give examples of functions which demonstrate covariance and contravariance in the cases of both overloading and overriding in Java? [closed]
Covariance: class Super { Object getSomething(){} } class Sub extends Super { String getSomething() {} } Sub#getSomething is covariant because it returns a subclass of the return type of Super#getSomething (but fullfills the contract of Super.getSomething()) Contravariance class Super{ void doSomething(String parameter) } class Sub extends Super{ void doSomething(Object parameter) } Sub#doSomething is contravariant because … Read more