Ricocotech Posted April 25, 2020 Posted April 25, 2020 What's up guys? So, I'm taking a programming course on my spare time because I want to learn how to make mods for Skyrim and Fallout. Since there's a lot of programmers here, I'd thought I'd ask for a bit of help here. I'm having trouble with learning Polymorphism. Anyone able to help me with questions 2 and 3? I've also put the java file for anyone to look at too. Any help is much appreciated. TestPolymorphism.java
Tyrant99 Posted April 25, 2020 Posted April 25, 2020 This is basically just another type of variable. You know how you can make different variables right? Float variable, Int variable, bool variable, etc. With polymorphism, just think of the class as the variable, you can also have functions as variables. - I'm more familiar with C#, and in that language these are 'delegates'. a is a placeholder for the Parent class, both of the subclasses extend that class so it can be set to them. In the below, a is first set to subclass1, and calls the function in subclass1, after that it gets set to subclass2, and calls the function in subclass2. That last line, a.Print (); is the equivalent of writing subclass2.Print(); It seems like a fancy concept, but it's basically just another type of variable, instead of an int or something you can think of it as a 'class' variable.
Ricocotech Posted April 26, 2020 Author Posted April 26, 2020 Ah gotcha. That's a lot easier than I thought. Thank you so much for your help.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.