Hi,
I thought I had this right, and I wrote a little example which confirmed it, but I'd still like a little extra confirmation in case there are deeper issues involved here.
If I have a type (b) which extends another type (a) and they both have the same function or method. If, in my program, I have an object which was created as a type b, but in order to achieve polymorphism, I have it as a type a, and then call that method, am I correct in thinking that it is actually the method of b which will be executed?
I am ( for the sake of polymorphism ) treating it as a type a, but it is in fact, a type b, so that's the method that gets called, right? And only that method?
My example I used to verify :
It executes b's function, even though I have it cast as a type a. If I remove the call to Super, type a's function is never called. So I think that confirms what I believed to be the case, right? No deeper issues here?
I thought I had this right, and I wrote a little example which confirmed it, but I'd still like a little extra confirmation in case there are deeper issues involved here.
If I have a type (b) which extends another type (a) and they both have the same function or method. If, in my program, I have an object which was created as a type b, but in order to achieve polymorphism, I have it as a type a, and then call that method, am I correct in thinking that it is actually the method of b which will be executed?
I am ( for the sake of polymorphism ) treating it as a type a, but it is in fact, a type b, so that's the method that gets called, right? And only that method?
My example I used to verify :
Type A Function PrintSomething() Print "DO NOT WANT TO PRINT ONLY THIS" End Function End Type Type B Extends A Function PrintSomething() Super.PrintSomething() Print "I WANT TO PRINT THIS TOO" End Function End Type Function CreateThing:A() Return New B End Function Global Thing:A=CreateThing() Thing.PrintSomething()
It executes b's function, even though I have it cast as a type a. If I remove the call to Super, type a's function is never called. So I think that confirms what I believed to be the case, right? No deeper issues here?