Question
The Plant class has one instance variable called name. Tree inherits from Plant and adds a height instance variable. All classes have the usual constructors,
The Plant class has one instance variable called name. Tree inherits from Plant and adds a height instance variable. All classes have the usual constructors, accessors, mutators and toString.
Identify any compiler errors in the program segment below. Explain what each error is and why it occurs.
If we remove the statements with errors, so that the program runs, what output will be produced by the 2 print statements? Explain why you get that output.
Plant p = new Plant( No Name );
System.out.println(p); // what output is produced here? why?
p = new Tree(Douglas Fir, 100 );
System.out.println(p); // what output is produced here? why?
p.setHeight(200);
Tree t = new Plant( some plant );
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