I'm a very straightforward data science student in last year before master graduation. I like to learn bottom-up step by step and go through the logical discovery process myself as much as possible
You an Animal class with children classes Herbivore and Carnivore for example. Then each child implements its own overriden version of function feed ().
For herbivores:
-find herb
-eat herb
For carnivores:
-find prey
-hunt prey
-eat
Even when the implementation is different for each kind of animal, you know that for any animal you can call the function feed for it and it will have the right behavior, this is Polymorphism.
Now imagine you have two pokemons in the pension and one day you come and the okd lady says "Your pokemons came back wih an egg, we don't know where they found it but here it is". So you got a behavior: receive an egg. But there is some internal hidden behavior : You don't know where it comes from. You know what happens but not how. This is encapsulation; you have access to some interface function but not access to the parameters it plays with
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You an Animal class with children classes Herbivore and Carnivore for example. Then each child implements its own overriden version of function feed ().
For herbivores:
-find herb
-eat herb
For carnivores:
-find prey
-hunt prey
-eat
Even when the implementation is different for each kind of animal, you know that for any animal you can call the function feed for it and it will have the right behavior, this is Polymorphism.
Now imagine you have two pokemons in the pension and one day you come and the okd lady says "Your pokemons came back wih an egg, we don't know where they found it but here it is". So you got a behavior: receive an egg. But there is some internal hidden behavior : You don't know where it comes from. You know what happens but not how. This is encapsulation; you have access to some interface function but not access to the parameters it plays with