46 Overriding methods
Friendly supplies a new text() body. The first call is made through a Greeting variable but still dispatches to the Friendly implementation.
norm
class Greeting {
public String text() { return "hello" }
}
class Friendly extends Greeting {
public String text() { return "hi" }
}
main() {
Greeting greeting = Friendly()
printLine(greeting.text())
printLine(Friendly().text())
}Expected output:
text
hi
hiTry it: Replace Friendly() with Greeting() in the first assignment.
Precise rules: Reference.