7- Upcasting and Downcasting

at the end of the lecture prof Mosh describe how to down casting but I think there is a little bit prop with me how we can represent “Hello” here as we give it to control object I know that we did not override toString() method on UiControl but I wonder how we override it on UiControl so that we can present the text we set it to control at the console?



Did you write the UiControl and TextBox classes? If so you can override their toString() with something like this.

public String toString() {
  return "whatever you want to return";

If you did not write those classes, then potentially you can extend TextBox and override toString() on your child class, and use your class instead of TextBox.