Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following class declarations. public class Tree { private String treeVariety; public Tree() { treeVariety = Oak; } public Tree(String variety) { treeVariety =

Consider the following class declarations.

public class Tree

{

private String treeVariety;

public Tree()

{

treeVariety = "Oak";

}

public Tree(String variety)

{

treeVariety = variety;

}

}

public class DeciduousTree extends Tree

{

public DeciduousTree(String variety)

{

super();

}

}

public class EvergreenTree extends Tree

{

public EvergreenTree(String variety)

{

super(variety);

}

}

The following code segment appears in a method in another class.

DeciduousTree tree1 = new DeciduousTree("Maple");

EvergreenTree tree2 = new EvergreenTree("Fir");

Which of the following best describes the result of executing the code segment?

A. Object tree1 is created using the DeciduousTree constructor, which uses super to set tree1s treeVariety attribute to "Maple". Object tree2 is created using the EvergreenTree constructor, which uses super to set tree2s treeVariety attribute to "Fir".

B. Object tree1 is created using the DeciduousTree constructor, which uses super to set tree1s treeVariety attribute to "Oak". Object tree2 is created using the EvergreenTree constructor, which uses super to set tree2s treeVariety attribute to "Fir".

C. Object tree1 is created using the DeciduousTree constructor, which uses super to set tree1s treeVariety attribute to "Oak". Object tree2 is created using the EvergreenTree constructor, which uses super to set tree2s treeVariety attribute to "Oak".

D. The code segment does not compile because the DeciduousTree and EvergreenTree constructors should not take a parameter.

E. The code segment does not compile because the DeciduousTree and EvergreenTree constructors do not correctly call a Tree constructor.

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

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions

Question

LO5 Illustrate the steps in developing a base pay system.

Answered: 1 week ago

Question

LO3 Outline strategic compensation decisions.

Answered: 1 week ago