Java OOPs Quiz - SCJP
Casual Mode - Take your time!
1 / 10
Correct
0
Incorrect
0
Score
0%
Multiple Choice
Which statement is true for the following code?
public class Plant {
private String name;
public Plant(String name) { this.name = name; }
public String getName() { return name; }
}
public class Tree extends Plant {
public void growFruit() { }
public void dropLeaves() { }
}
- The code will compile without changes.
- The code will compile if public Tree() { Plant(); } is added to the Tree class.
- The code will compile if public Plant() { Tree(); } is added to the Plant class.
- The code will compile if public Plant() { this("fern"); } is added to the Plant class.