Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started