| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice Test
Share
easy Solved by 2 students
Constructor Chaining in Inheritance
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2suhanakochhar00611 1m 45s -5
#3psak1201 1m 50s -120
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy