Jump to content
IGNORED

Programming Help


Recommended Posts

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.

 

 

 


Annotation 2020-04-23 163511.png
 

 

TestPolymorphism.java

Link to comment

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.

 

image.png.c3727494c01220b6d511387efe41f586.png

 

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.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...