Inheritance Constructor Call Order
Given the initial execution of the following code:
Lychee l = new Lychee();
If the class hierarchy involves multiple constructor calls each printing a unique statement, determine the output using these classes:
public class Seed {
Seed() { System.out.println("Planting a seed"); }
}
public class Fruit extends Seed {
Fruit() { System.out.println("Growing a fruit"); }
}
public class Lychee extends Fruit {
Lychee() { System.out.println("Lychee is sweet"); }
}
Which sequence accurately reflects what will be printed out?:
A
Planting a seed
Lychee is sweet
B
Lychee is sweet
C
Growing a fruit
Lychee is sweet
Planting a seed
D
Planting a seed
Growing a fruit
Lychee is sweet
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | zhanghan003 | 1 | 1 | 0m 00s | 100 |
| #2 | zgj07310417 | 1 | 1 | 0m 44s | 56 |
| #3 | parth.taur227 | 1 | 1 | 1m 27s | 13 |
| #4 | meromaroseif | 0 | 1 | 0m 45s | -55 |
Items per page:
10
1 – 4 of 4
APFIVE