Given the following class descriptions, make an inheritance hierarchy chain in C
ID: 3736941 • Letter: G
Question
Given the following class descriptions, make an inheritance hierarchy chain in C#:
Class 1: ChocolateCake - Has vanilla frosting and candels. Is good for special occasions like a birthday party. Chocolate cake has three layers to it.
Class 2: Cupcake - Smaller than a cake. Has orange frosting and multiple can be created in one batch. Doesn't have candles and is not really good for birthday parties (cupcakes are good for birthday parties, just for this example they won't be) and has only one layer
Explanation / Answer
using System;
namespace n{
class Cake{}
class ChocolateCake : Cake{
private int layer;
private int frosting;
private int candles;
public ChocolateCake{}
public ChocolateCake (int l, int f, int c){
layer = l;
frosting = f;
candles = c;
}
}
class CupCake : Cake{
private int layer, frosting,candles;
public CupCake{}
public CupCake(int l, int f, int c){
layer = l; frosting = f; candles = c;
}
}
public class Party{
static void Main(string[] args){
ChocolateCake party1 = new ChocoloateCake(3,2,10); // Party1 having chocolate cake
for ( int person = 10; person <= 10; person++){
CupCake c = new CupCake(1,1,0); // Party 2 having Cupcake , Assuming 10 persons in a party, each cupcake for each person
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.