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
Get step-by-step solutions from verified subject matter experts
