Click here to Skip to main content
16,013,918 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to set ToolTip to ToolStripButton? Pin
Saksida Bojan12-Feb-10 19:46
Saksida Bojan12-Feb-10 19:46 
AnswerMessage Closed Pin
12-Feb-10 20:43
stancrm12-Feb-10 20:43 
GeneralRe: How to set ToolTip to ToolStripButton? Pin
arichikato13-Feb-10 7:47
arichikato13-Feb-10 7:47 
QuestionInaccessible due to its protection level [modified] Pin
ASPnoob12-Feb-10 16:38
ASPnoob12-Feb-10 16:38 
AnswerRe: Inaccessible due to its protection level Pin
Wes Aday12-Feb-10 17:14
professionalWes Aday12-Feb-10 17:14 
GeneralRe: Inaccessible due to its protection level Pin
ASPnoob12-Feb-10 17:25
ASPnoob12-Feb-10 17:25 
GeneralRe: Inaccessible due to its protection level Pin
Wes Aday12-Feb-10 17:37
professionalWes Aday12-Feb-10 17:37 
AnswerRe: Inaccessible due to its protection level Pin
DaveyM6912-Feb-10 22:56
professionalDaveyM6912-Feb-10 22:56 
The fields name and salary are private which is as it should be. If you want these to be accessible to inheriting classes then you have a couple of choices.

1 Change the fields access modifiers - this is not recommended however! You could use (from least bad to worst)
protected - they will only be visible to TeamManagement and classes derrived from it.
internal - they will be visible to all classes in the assembly.
public - they will be visible to everyone.

2. Expose them via a property. I've rewritten your code below that way, and made a couple of other changes to make it more usable.
C#
namespace Inheritance
{
    public enum TeamManagementType
    {
        TeamManagement = 0,
        Executive = 1,
        Owner = 2,
    }

    public class TeamManagement
    {
        private string name;
        private double salary;
        private TeamManagementType teamManagementType;

        public TeamManagement(string name, double salary)
            : this(name, salary, TeamManagementType.TeamManagement)
        { }
        internal TeamManagement(string name, double salary, TeamManagementType teamManagementType)
        {
            this.name = name;
            this.salary = salary;
            this.teamManagementType = teamManagementType;
        }

        public string Name
        {
            get { return name; }
        }
        public double Salary
        {
            get { return salary; }
        }

        public override string ToString()
        {
            return string.Format("{0}[{1}, {2}]", teamManagementType, name, salary);
        }
    }

    public class Executive : TeamManagement
    {
        private string role;

        public Executive(string name, double salary, string role)
            : this(name, salary, role, TeamManagementType.Executive)
        { }
        internal Executive(string name, double salary, string role, TeamManagementType teamManagementType)
            : base(name, salary, teamManagementType)
        {
            this.role = role;
        }

        public string Role
        {
            get { return role; }
        }
    }

    public class Owner : Executive
    {
        public Owner(string name, double salary, string role)
            : base(name, salary, role, TeamManagementType.Owner)
        { }
    }
}
Notice by using the changes I have amde, the base ToString method hasn't needed to be rewritten in the derived classes so the properties haven't actually been needed as yet, but I've included them as no doubt they will be later.
Dave

Tip: Passing values between objects using events (C#)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

AnswerRe: Inaccessible due to its protection level Pin
Luc Pattyn13-Feb-10 1:26
sitebuilderLuc Pattyn13-Feb-10 1:26 
QuestionCall a .aspx web-form from Microsoft CRM 4 Pin
quercus12-Feb-10 12:56
quercus12-Feb-10 12:56 
QuestionTTF file format Pin
sduhd12-Feb-10 12:13
sduhd12-Feb-10 12:13 
AnswerRe: TTF file format Pin
harold aptroot12-Feb-10 12:52
harold aptroot12-Feb-10 12:52 
QuestionWindows service & Timers Pin
koleraba12-Feb-10 10:06
koleraba12-Feb-10 10:06 
AnswerRe: Windows service & Timers Pin
PIEBALDconsult12-Feb-10 10:38
mvePIEBALDconsult12-Feb-10 10:38 
GeneralRe: Windows service & Timers Pin
koleraba12-Feb-10 11:01
koleraba12-Feb-10 11:01 
GeneralRe: Windows service & Timers Pin
PIEBALDconsult12-Feb-10 14:09
mvePIEBALDconsult12-Feb-10 14:09 
GeneralRe: Windows service & Timers Pin
koleraba12-Feb-10 22:36
koleraba12-Feb-10 22:36 
GeneralRe: Windows service & Timers Pin
PIEBALDconsult13-Feb-10 3:20
mvePIEBALDconsult13-Feb-10 3:20 
AnswerRe: Windows service & Timers Pin
DaveyM6912-Feb-10 10:47
professionalDaveyM6912-Feb-10 10:47 
GeneralRe: Windows service & Timers Pin
koleraba12-Feb-10 11:04
koleraba12-Feb-10 11:04 
QuestionRe: Windows service & Timers Pin
koleraba12-Feb-10 12:39
koleraba12-Feb-10 12:39 
AnswerRe: Windows service & Timers Pin
22491714-Feb-10 17:33
22491714-Feb-10 17:33 
GeneralRe: Windows service & Timers Pin
koleraba14-Feb-10 23:50
koleraba14-Feb-10 23:50 
QuestionA few pointers toward design Pin
Saksida Bojan12-Feb-10 9:00
Saksida Bojan12-Feb-10 9:00 
AnswerRe: A few pointers toward design Pin
Dan Mos12-Feb-10 9:13
Dan Mos12-Feb-10 9:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.