Show me a class in your code where there could be either static or dynamic binding.
Write some mock code on this paper showing how you would set the static type and
dynamic type of a variable.
public abstract class HedgehogDialogue
{
public virtual string[] GetCurrentResponses(){
//public string[] GetCurrentResponses(){
return (new string [] {"wow! did you comment out virtual? this is exactly what you need for the oral exam!"});
}
}
public class ShadowDialogue : HedgehogDialogue
{
//overridden function for oral exam
public override string[] GetCurrentResponses() {
//public string[] GetCurrentResponses(){
return(currentDialogueIndex < playerResponses.Count) ? playerResponses[currentDialogueIndex] : new string[0];
}
}
Virtual Function:GetCurrentResponses Main Code:Source Code
HedgehogDialogue sonicDialogue = new SonicDialogue(affectionManager);
Choose a dynamically bound method. What method gets called now?
Change the dynamic type. What method gets called now?
Pick a statically bound method. Which one would be called in each of the two previous
cases?
Notice in the video:
Originally the GetCurrentResponses() in the subclass is called
All I did was remove the words virtual and override and now the GetCurrentResponses() in the superclass is called. (The dialog is different now)