Multiple choice technology

Given: 1. public class Plant { 2. private String name; 3. public Plant(String name) { this.name = name; } 4. public String getName() { return name; } 5. } 1. public class Tree extends Plant { 2. public void growFruit() { } 3. public void dropLeaves() { } 4. } Which statement is true?

  1. The code will compile without changes.

  2. The code will compile if public Tree() { Plant(); } is added to the Tree class.

  3. The code will compile if public Plant() { Tree(); } is added to the Plant class.

  4. The code will compile if public Plant() { this("fern"); } is added to the Plant class

  5. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Plant has only a parameterized constructor. Tree's no-arg constructor implicitly calls super(), which fails because Plant has no no-arg constructor. Adding public Plant() { this("fern"); } provides the missing no-arg constructor.