Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Define a class and name it as Lion. Add the following inside the class. 1. Define instance variables species, color, weight 2. Add a

image text in transcribed

java

Define a class and name it as "Lion". Add the following inside the class. 1. Define instance variables species, color, weight 2. Add a parameterized constructor which will take 3 parameters. Inside the constructor initializes the attributes with the parameters passed to the constructor. 3. Add the following methods. a. public void hunt(String prey) - Inside the method, print "species like to hunt prey." where species is the value of the species attribute and prey is the value of the parameter passed to the method. b. public double getWeight() - the method should return the weight attribute. c. public void display() - inside the method, print the value of all three attributes. Question 2: [8] Define a class and name it as "TestLion". Define the main method inside the class. Inside the main, do the following. 1. Create an object of Lion class name="Royal Bengal Tiger", color=" Golden" and weight =200. Store the reference to a variable name myLion. 2. Call the hunt(...) method using the myLion variable and pass "deer" as the parameter of the method. 3. Call the display(...) method using the myLion. - What is the output of this method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+j Explain IHRMs role in global HR research.

Answered: 1 week ago

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago