Object-Oriented Program Design, Exercises of Computer Science

I have taken this question and answer from computer Science. The topic of which is Object-Oriented Program Design.

Typology: Exercises

2014/2015

Available from 05/14/2024

farook-ali
farook-ali 🇮🇳

88 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5

Partial preview of the text

Download Object-Oriented Program Design and more Exercises Computer Science in PDF only on Docsity!

Object-Oriented Program Design Consider the code below: private static class Philosopher { private String name; private String favoriteSubject; public Philosopher(String n, String f) { name =n; favoriteSubject = f; } public String getName() { return name; } public String getFavoriteSubject() { The rest is given below return favoriteSubject; } public void speak() { System.out.printIn("Hello, World! My name is "+tname + ". My favorite subject is "+favoriteSubject); } } private static class Nominalist extends Philosopher { boolean franciscan; public Nominalist(String n,boolean frank) { super(n,"logic"); franciscan = frank; The rest is given below return "Perhaps it was Durandus of St. Pourcain — scandalous, a Dominican nominalist!"; J } 4. If you wished to make a toString() method for both Philosopher and Nominalist, using the same output as in each class' current speak() methods, what would be the best way to organize your code? |. Have toString() invoke both classes' speak() methods. ll. Have the speak() method invoke the new toString() method. The rest is given below lll. Create a new subclass and write the toString() method in that.