Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Bird { private int beakStrength; public void Bird(int input) { beakStrength = input; } public void setBeakStrength(int strength) { beakStrength = strength; }

public class Bird

{

private int beakStrength;

public void Bird(int input)

{

beakStrength = input;

}

public void setBeakStrength(int strength)

{

beakStrength = strength;

}

}

public class Hawk extends Bird

{

private int talonStrength;

public Hawk(int talon, int beak)

{

super(beak);

talonStrength = talon;

}

}

The following statement appears in a method in another class.

Bird b = new Hawk(5, 8);

Which of the following best describes the effect of executing the statement?

  • A) The Bird variable b is instantiated as a Hawk. The instance variable talonStrength is initialized with the value from the parameter talon. The Hawk constructor cannot set the instance variable beakStrength because a subclass does not have access to a private variable in its superclass.

  • B) The Bird variable b is instantiated as a Hawk. The call super(beak) returns a value from the instance variable beakStrength in the superclass and makes it accessible in the subclass. The instance variable talonStrength is then initialized with the value from the parameter talon.

  • C) The Bird variable b is instantiated as a Hawk. The instance variable talonStrength is initialized with the value from the parameter talon. No other initializations are made to any instance variables.

  • D) The Bird variable b is instantiated as a Hawk. The call super(beak) invokes the Bird constructor and initializes the instance variable beakStrength with the value from the parameter beak. The instance variable talonStrength is then initialized with the value from the parameter talon.

  • E) The code segment will not execute because the Bird variable b cannot be instantiated as a Hawk.

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_2

Step: 3

blur-text-image_3

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions