Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

Define a random number. How is it different from a random variate?

Answered: 1 week ago

Question

2 What supply is and what affects it.

Answered: 1 week ago

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago