Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
private void button_Click(object sender, EventArg e)
{
	BirthdayParty partyOn = new BirthdayParty();
	
	MessageBox.Show( partyOn.getMessage("Shadid") );
	MessageBox.Show( partyOn.getPresent (8) );

	MessageBox.Show( partyOn.getParty( true) );
}


C#
Class HappyBirthday
{
    private string birthdayMessage;
    private string presentString;
    public HappyBirthday()
    {
        presentString = "Number of presents: ";
        birthdayMessage = "Happy Birthday";
}
public string getMessage(string givenName)
{
    return birthdayMessage + givenName;
}
public string getPresents(int numPresents)
{
    presentString = presentString + numPresents.ToString();
    return presentString;
}
}


C#
//====================================
//           A DERIVED CLASS
//====================================
class BirthdayParty : HappyBirthday
{
//=====================================================
//  DEFAULT CONSTRUCTOR CALLS THE base () CONSTRUCTOR
//=====================================================
public BirthdayParty() : base()
{
}
//=================
//      METHOD
//=================
public string getParty (bool haveParty)
{
    if (haveParty == true)
    return "Enjoy your party!";
    }
    else
    {
    return  "Sorry – No party for you!";
    }
}
}
Posted
Updated 3-Sep-14 2:59am
v3
Comments
ZurdoDev 3-Sep-14 8:53am    
I give up. What is the problem with it?
Member 9538830 3-Sep-14 9:13am    
Does not work. Reports an error. The example is from a book.
ZurdoDev 3-Sep-14 9:23am    
And the error is?
Member 9538830 3-Sep-14 19:15pm    
Errors:
//===============
// DERIVED CLASS
//===============
class BirthdayParty : HappyBirthday1 // Kakva je ovo greška???

Error 1 The type or namespace name 'HappyBirthday1' could not be found (are you missing a using directive or an assembly reference?)
………………………………………………………………………………………………………………………………………………………………….

private void button1_Click(object sender, EventArgs e)
.
.
.
MessageBox.Show( partyOn.getMessage("Shadid"));
MessageBox.Show(partyOn.getPresent(8));

Error 2 'BirthdayParty' does not contain a definition for 'getMessage' and no extension method 'getMessage' accepting a first argument of type 'BirthdayParty' could be found (are you missing a using directive or an assembly reference?)
Error 3 'BirthdayParty' does not contain a definition for 'getPresent' and no extension method 'getPresent' accepting a first argument of type 'BirthdayParty' could be found (are you missing a using directive or an assembly reference?)
ZurdoDev 3-Sep-14 20:38pm    
That error won't come from the code you posted. The error is saying it does not know what HappyBirthday1 is. Note, you have a 1 on the end of HappyBirthday.

1 solution

when you are asking a question, you need to post the error which you are getting with your code, so that we can solve it easily
any way i have posted my code which i have tested with your code

replace your code with below code

C#
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BirthdayParty partyOn = new BirthdayParty();
	
	MessageBox.Show( partyOn.getMessage("Shadid"));
	MessageBox.Show( partyOn.getPresents(8) );
 
	MessageBox.Show( partyOn.getParty( true) );
        }
    }

    class HappyBirthday
{
    private string birthdayMessage;
    private string presentString;
    public HappyBirthday()
    {
        presentString = "Number of presents: ";
        birthdayMessage = "Happy Birthday";
}
public string getMessage(string givenName)
{
    return birthdayMessage + givenName;
}
public string getPresents(int numPresents)
{
    presentString = presentString + numPresents.ToString();
    return presentString;
}
}
 
 
//====================================
//           A DERIVED CLASS
//====================================
class BirthdayParty : HappyBirthday
{
//=====================================================
//  DEFAULT CONSTRUCTOR CALLS THE base () CONSTRUCTOR
//=====================================================
public BirthdayParty() : base()
{
}
//=================
//      METHOD
//=================
public string getParty (bool haveParty)
{
    if (haveParty == true)
    {
    return "Enjoy your party!";
    }
    else
    {
    return  "Sorry – No party for you!";
    }
}
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900