Skip to main content

Section 5.11 Code Practice with Object Oriented Concepts

Activity 5.11.1.

Write a method that overloads the talk method by taking in a name and printing Hello with that name.

Activity 5.11.2.

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”.

Activity 5.11.3.

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.

Activity 5.11.4.

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.

Activity 5.11.5.

Overload the greet method to just print Hello if not given any parameters. It should print Hello and then Hello Sansa.

Activity 5.11.6.

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.

Activity 5.11.7.

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.

Activity 5.11.8.

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.

Activity 5.11.9.

Correctly finish the Dog subclass for the following Animal class. Override the methods speak() to print woof and eat() to print num num.

Activity 5.11.10.

Override the compareTo method so that it returns a positive 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.

Activity 5.11.11.

Override the Person class’s speak method inside the Student class. Make the method print I'm a student.
You have attempted of activities on this page.