Constructor Chaining in Inheritance
Consider the following class definitions.
public class Bread
{
private String name;
Bread()
{
name = "bread";
System.out.println("Freshly baked bread smells good");
}
public String toString()
{
return name;
}
}
public class Pastry extends Bread
{
Pastry()
{
System.out.println("Baking pastry is an art");
}
}
public class Croissant extends Pastry
{
Croissant()
{
System.out.println("Croissants taste buttery");
}
}
What is printed to the console when the following statement is executed?
Croissant c = new Croissant();
A
Freshly baked bread smells good
B
Croissants taste buttery
Freshly baked bread smells good
C
Freshly baked bread smells good
Baking pastry is an art
Croissants taste buttery
D
Croissants taste buttery
Baking pastry is an art
Freshly baked bread smells good
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 1 | 0m 00s | 100 |
| #2 | suhanakochhar006 | 1 | 1 | 1m 45s | -5 |
| #3 | psak12 | 0 | 1 | 1m 50s | -120 |
APFIVE