In this activity, you will learn when and how to use the super keyword. You will show
Question:
In this activity, you will learn when and how to use the super keyword. You will show a tortoise and turtle who are both reptiles. You will use the reptile whoAmI and modify it to get the required output. Please follow the steps below:
Steps:
Read the explanation and observe how the super keyword is used in the Tortoise.java file.
Show a class Turtle that inherits from Reptile.
Show an instance variable that will hold the length of time our turtle will hold its breath.
// 4. Make a constructor that takes in the same parameters as the reptile constructor and then passes those parameters into the super constructor. Also, add a parameter in the constructor for breath and then initialize it.
Override the whoAmI() method. Make sure to print this out: " and a turtle. My skin is scaly utilizing the super keyword. I can hold my breath for 60 minutes."
Show a Tortoise object that utilized our Tortoise constructor which takes in the name, limbs, and life. Assign those values to our object and get the return. The name should be Baloo, limbs should be bent and stubby, and life should be 150 years.
Show a Turtle object that utilized our Turtle constructor which takes in the name, limbs, life, and breath. The Name should be Squirtle, limbs should be flippers, life should be 50 and breath should be 60.
Call the whoAmI method using your Turtle object.
Test:
Use the test provided.
Sample output:
My name is Baloo. I am a reptile and a tortoise. My skin is scaly. My name is Squirtle. I am a reptile and a turtle. My skin is scaly. I can hold my breath for 60 minutes.
class Main { public static void main(String[] args) {
// 6.Show a Tortoise object and pass values for name, limbs, and life into the parenthesis. The name should be Baloo, limbs should be bent and stubby, and life should be 150 years.
// 7. Call the whoAmI method using your Tortoise object.
// 8. Show a Turtle object that utilized our Turtle constructor which takes in the name, limbs, life, and breath. The Name should be Squirtle, limbs should be flippers, life should be 50 and breath should be 60.
// 9. Call the whoAmI method using your Turtle object. } }
Organizational Behaviour Concepts Controversies Applications
ISBN: 978-0132310314
6th Canadian Edition
Authors: Nancy Langton, Stephen P. Robbins, Timothy A. Judge, Katherine Breward