Question

In: Computer Science

Read the following pseudocode class definitions: Class Plant Public Module message() Display "I'm a plant." End...

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.


the language is python.

Solutions

Expert Solution

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:)


Related Solutions

Write the following Java code into Pseudocode import java.util.*; public class Main { // Searching module...
Write the following Java code into Pseudocode import java.util.*; public class Main { // Searching module public static void score_search(int s,int score[]) { // Initialise flag as 0 int flag=0; // Looping till the end of the array for(int j=0;j<10;j++) { // If the element is found in the array if(s==score[j]) { // Update flag to 1 flag=1; } } // In case flag is 1 element is found if(flag==1) { System.out.println("golf score found"); } // // In case flag...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int hours, shift, retirement = 0; do { System.out.print("Enter the number of hours worked (>0): "); hours = scanner.nextInt(); } while (hours <= 0); do { System.out.print("Enter shift [1 2 or 3]: "); shift = scanner.nextInt(); } while (shift < 1 || shift > 3); if (shift == 2 || shift ==...
6-Write a module in pseudocode called magicSix(), which accepts two integers and displays a message “Magic...
6-Write a module in pseudocode called magicSix(), which accepts two integers and displays a message “Magic 6!” if either of the two integers is a 6 or if their sum or difference is a 6. Otherwise, the program will display “Not a magic 6.” Note, you will need to determine the larger number when calculating the difference, to get a positive difference. You cannot use any built-in Python functions to do this. Type your pseudocode into your answer document. 7-...
Read and understand the pseudocode of problem R2.19 in java from the end of chapter 2...
Read and understand the pseudocode of problem R2.19 in java from the end of chapter 2 in your textbook. In a Java class named WeekDays, write a java program that reads an input int between (0-6), and displays the corresponding day for that given input as below: Enter a number (0-6): 2 ** 2 is Tue ** !!! NO if-else conditions
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {   ...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {    public static void main(String[] args) {        //Generate random array for test and copy that into 3 arrays        int[] arr1=new int[20];        int[] arr2=new int[20];        int[] arr3=new int[20];        int[] arr4=new int[20];        Random rand = new Random();        for (int i = 0; i < arr1.length; i++) {            //Generate random array...
In this module, we read Sarah Deer’s monograph, The Beginning and End of Rape, in which...
In this module, we read Sarah Deer’s monograph, The Beginning and End of Rape, in which she explores the historical and ongoing brutal effects of sexual violence on Native women. In your critical reflection, please address these three questions: 1. First explain why describing the rape of Native women as an “epidemic” is inaccurate. In other words, what about rape as a phenomenon warrants a different description? 2. Next discuss how we can consider the combination of federal laws and...
Read the following email message, and do as directed: (10 marks each) Analyze the message and...
Read the following email message, and do as directed: (10 marks each) Analyze the message and point out the weaknesses, mention the points citing an example from the message. Rewrite the message to improve the effectiveness. Subject: Printing costs are out of control I am not sure what everyone is printing or even who is doing all the unnecessary printing, but a look in the recycling bin showed a number of areas of waste: Printouts of email messages Unneeded copies...
assume that the following pseudocode is executed in a program module main declare x = 1...
assume that the following pseudocode is executed in a program module main declare x = 1 declare sum = 0 declare max = 5 while ( x < max) Display "x is ", x set x = x + 1 set sum = s + x end while end module after the execution of this program the final value of x is_____ and the final value of sum is_____
Write a Class called Module with the following attributes: module code, module name, list of lecturers...
Write a Class called Module with the following attributes: module code, module name, list of lecturers for the module (some modules may have more than one lecturer – we only want to store their names), number of lecture hours, and module description. Create a parameterised (with parameters for all of the class attributes) and a non-parameterised constructor, and have the accessor and mutator methods for each attribute including a toString method. Write a class Student with the following attributes: student...
WRITE THIS JAVA CODE IN PSEUDOCODE!! import java.util.Scanner; public class License { public static void main(String[]...
WRITE THIS JAVA CODE IN PSEUDOCODE!! import java.util.Scanner; public class License { public static void main(String[] args) { char correctAnswers[] = {'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'}; char userAnswers[] = new char[correctAnswers.length]; Scanner scanner = new Scanner(System.in); for (int i = 0; i < userAnswers.length; i++) { String answer = ""; System.out.printf("Question #%d. Enter your answer( A, B, C or D): ", i + 1); do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT