Why does an overridden function in the derived class hide other overloads of the base class?

Consider the code : #include <stdio.h> class Base { public: virtual void gogo(int a){ printf(” Base :: gogo (int) \n”); }; virtual void gogo(int* a){ printf(” Base :: gogo (int*) \n”); }; }; class Derived : public Base{ public: virtual void gogo(int* a){ printf(” Derived :: gogo (int*) \n”); }; }; int main(){ Derived obj; … Read more

Is List a subclass of List? Why are Java generics not implicitly polymorphic?

I’m a bit confused about how Java generics handle inheritance / polymorphism. Assume the following hierarchy – Animal (Parent) Dog – Cat (Children) So suppose I have a method doSomething(List<Animal> animals). By all the rules of inheritance and polymorphism, I would assume that a List<Dog> is a List<Animal> and a List<Cat> is a List<Animal> – … Read more

Why do we need virtual functions in C++?

I’m learning C++ and I’m just getting into virtual functions. From what I’ve read (in the book and online), virtual functions are functions in the base class that you can override in derived classes. But earlier in the book, when learning about basic inheritance, I was able to override base functions in derived classes without … Read more

Polymorphism vs Overriding vs Overloading

The clearest way to express polymorphism is via an abstract base class (or interface) public abstract class Human{ … public abstract void goPee(); } This class is abstract because the goPee() method is not definable for Humans. It is only definable for the subclasses Male and Female. Also, Human is an abstract concept — You cannot create … Read more