In: Computer Science
Read the following pseudocode class definitions:
Class Plant
Public Module message()
Display "I'm a plant."
End Module
End Class
Class Tree Extends Plant
Public Module message()
Display "I'm a tree."
End Module
End Class
Given these class definitions, determine what the following pseudocode will display:
Declare Plant p
Set p = New Tree()
Call p.message()
Discuss how algorithms address object-oriented classes and objects.
This is called polymorphic behavior of the object , In Up casting (Assigning parent reference to Child object called up casting)
the method in parent class overrided by the Child class , In the following example message method is overrided by Tree class message method and execute its implementation...
/*******************************main.py*******************/
class Plant:
def message(self):
print( "I'm a plant.")
class Tree(Plant):
def message(self):
print("I'm a tree.") #overrided method
p = Tree()
p.message()#calling method by super class object reference but the
method will overrided by subclass Tree
Please let me know if you have any doubt or modify the answer, Thanks:)