Is it ok if i understand classes like Polymorphisim Abstractions etc but i dont know how to use them

Like i understand what polymorphisim is and different classes but when i get to the writing them myself part i freeze and dont know what exactly to do
3 Replies
ティナ
ティナ2mo ago
it is just a term to describe you have a base class reference and the base class defining some virtual method, you can call it and let the actual child class does the work without knowing what child class actually is it requires some sort of foresee, if you know you gonna to have multiple implementations of some type then you will use it
Ryan H.
Ryan H.2mo ago
In my opinion, if you don't know how to use it then you don't truly have a deep understanding. The quickest fix for this is to go online and find a few different examples of polymorphism in action and recognize the patterns between them. https://www.w3schools.com/cs/cs_polymorphism.php This page uses an animals example. Try to figure out a few different scenarios where polymorphism might be useful and try implementing those
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Ryan H.
Ryan H.2mo ago
Sorta like how a computer and a car get turned on in two different ways. A computer's turnOn() method might just involve pressing the start button. A car's implementation of turnOn() might involve turning the key in the ignition. Both a computer and car might inherit from a Machine base class

Did you find this page helpful?