Which statement is true?

Given:

1. public class Plant {
2. private String name;
3.
4. public Plant(String name) {
5. this.name = name;
6. }
7.
8. public String getName() {
9. return name;
10. }
11. }

1. public class Tree extends Plant {
2. public void growFruit() {
3. }
4.
5. public void dropLeaves() {
6. }
7. }

Which statement is true?

Given:

1. public class Plant {
2. private String name;
3.
4. public Plant(String name) {
5. this.name = name;
6. }
7.
8. public String getName() {
9. return name;
10. }
11. }

1. public class Tree extends Plant {
2. public void growFruit() {
3. }
4.
5. public void dropLeaves() {
6. }
7. }

Which statement is true?

A.
The code will compile without changes.

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

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

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

E.
The code will compile if public Plant() { Plant(“fern”); } is added to the Plant class.

Explanation:



Leave a Reply 1

Your email address will not be published. Required fields are marked *