Quiz 2
Quiz 2
a) In the Circle class, implement method overloading for the draw method to accept an additional
parameter of type int representing the radius.
b) In the Square class, implement method overloading for the draw method to accept an additional
parameter of type double representing the side length.
1
Question 4: Object Access (15 marks)
Consider the following code snippet:
1 class Animal {
2 protected String name;
3
4 Animal(String name) {
5 this.name = name;
6 }
7
8 void makeSound() {
9 System.out.println("Animal sound");
10 }
11 }
12
13 class Dog extends Animal {
14 Dog(String name) {
15 super(name);
16 }
17
18 // Implement method overriding for makeSound()
19 }
a) In the Dog class, implement method overriding for the makeSound method to print ”Bark!”.
b) Create an instance of the Dog class named myDog with the name ”Buddy”. Access the name
attribute and invoke the makeSound method.
End of Quiz