📚 Practice Mode
Java OOPs Quiz - SCJP
Learn at your own pace with hints and detailed explanations
1 / 10
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.