Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
10.10. Code Practice with Object Oriented Concepts¶
Write a method that overloads the talk method by taking in a name and printing “Hello” with that name.
Overloading is when several methods have the same name but different parameter types, order, or number. In this case, the original method had no parameters and we overloaded it by creating a talk method with a String parameter.
Edit this code so the class Beagle is a subclass of the Dog class. When you run the code it should print “woof!” and then “arf arf”
Add an equals method to this class that returns true if the current Dog and passed Dog have the same name. The code should print false twice then true twice.
Override the taste method from the Candy class in the Chocolate class to return “tastes chocolately”. It should print “tastes sweet!” and then “tastes chocolately”.
Overload the greet method to just print “Hello” if not given any parameters. It should print “Hello” and then “Hello Sansa”.
Add a call to Pet’s brag method before printing anything in Dog’s brag method (hint: use super to call an overridden method). It should print “I have the best pet!” and then “I have the best dog”.
Finish the Teacher constructor. Use super to use the Person construtor to set the fields inherited from Person. It should print “Destini 20” followed by “Erica 55 Masters in Teaching”.
Add public getter and setter methods to the Store class so its variables can be accessed by other classes. It should print the store’s name and address and then change both and print the new values.
Correctly finish the Dog subclass for the following Animal class. Override the methods speak() to print “woof” and eat() to print “num num”.
Override the compareTo method so that it returns a postive number if the current Person is older than the passed other and a negative number if they are younger. If their age is the same then return the compareTo result on the names.
Override the Person class’s speak function inside the Student class. Make the function print “I’m a student”.