You need to sign in to do that
Don't have an account?
Ken Koellner
Method override, do I have to cast to get more specific method
If I have a subclass that overrides a method in a superclass, do I have to cast a reference to get the more specific reference. The superclass is virtual, not abstract as it has to implement some logic.
Example class definition--
public virtual class MySuperClass { public virtual boolean myMethod () { // code goes here return result; } } public class MySubClass { public override boolean myMethod () { // code goes here return result; } }
Example call --
MySuperClass myObj = new MySubClass(); // Does this call MySuperClass.validate() or MySubClass.validte() ? Boolean result = myObj.myMethod(); // Do I have to do this to call MySubClass.validate() ? Boolean result = (myObj(MySubClass)).myMethod();
No, you don't need to cast. So essentially:
Hope this helps!
- Anup
All Answers
No, you don't need to cast. So essentially:
Hope this helps!
- Anup
Indeed you are correct.
I forgot that you can define classes in anonymous apex. I just ran this as an example to proove it --
Thanks! Yeah :) That's how I normally prove or disprove my suspicions when I am in doubt about the language feature. I use the Developer Console. It is my new best friend.
- Anup