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() { }
}
  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.
Change Mode