Professional Documents
Culture Documents
Objectives:
To define a subclass from a superclass through inheritance (§11.2).
To invoke the superclass’s constructors and methods using the super keyword (§11.3).
To override instance methods in the subclass (§11.4).
2. Implement a constructor in the `Animal` class to initialize the `name` and `sound`
attributes.
5. Implement a constructor in the `Bird` class that calls the superclass's constructor
using the `super` keyword and initializes the `wingSpan` attribute.
Method Overriding:
1. In the `Animal` class, create a method named `makeSound()` that prints the sound
of the animal.
2. Override the `makeSound()` method in the `Bird` class to make it specific for birds.
For example, print "Chirp!" for bird sounds.
Problem B
Objectives:
To distinguish differences between overriding and overloading (§11.5).
To explore the toString() method in the Object class (§11.6).
3. Explain the concept of method overloading and how it allows methods with the same
name but different parameter types in the same class.
6. Explain the concept of method overriding and how it allows a subclass to provide a
specific implementation for a method defined in its superclass.
1. In the `MathOperations` class, override the `toString()` method provided by the `Object`
class.
2. Implement the `toString()` method to return a string representation of the object, including
information about the class and its attributes.