Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 573753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:45:27+00:00 2026-05-13T13:45:27+00:00

I have an abstract class Employee and 2 other classes that extend it (Developer

  • 0

I have an abstract class Employee and 2 other classes that extend it (Developer and Manager). My problem is that when I whenever I create a Manager

Employee man = new Manager(1234567, 30, "Bob", "Pie")

and try to set it in the Manager field of a new Developer,

Employee codemonkey = new Developer(1234568, 20, "Code", "Monkey", (Manager)man)

I keep getting the ArgumentException that my Manager is null. I did some checks and it somehow becomes null when I try to set it with the Manager property in the constructor. Any advice as to why I’m getting this error would be greatly appreciated. TIA!

The code for each is below:

//Employee Class

public abstract class Employee
{
    string firstName, lastName;
    int id, yearsEmployed;

    //Names must be non-empty
    public string FirstName
    {
        get { return firstName; }
        set
        {
            if (!value.Equals(""))
            {
                firstName = value;
            }
            else
                throw new ArgumentException("name cannot be empty");
        }
    }
    public string LastName
    {
        get { return lastName; }
        set
        {
            if (!value.Equals(""))
            {
                lastName = value;
            }
            else
                throw new ArgumentException("name cannot be empty");
        }
    }
    // IDs must be strings consisting of exactly seven digits.
    public int ID
    {
        get { return id; }
        set
        {
            if (value.ToString().Length == 7)
            {
                id = value;
            }
            else
                throw new ArgumentException("ID must consist of 7 digits");
        }
    }
    // Years employed must always be non-negative.
    public int YearsEmployed
    {
        get { return yearsEmployed; }
        set
        {
            if (value >= 0)
            {
                yearsEmployed = value;
            }
            else
                throw new ArgumentException("Year employed must be non-negative");
        }
    }
    //Constructor
    public Employee(int id, int yearsEmployed,
                    string firstName, string lastName)
    {
        this.FirstName = firstName;
        this.LastName = lastName;
        this.ID = id;
        this.YearsEmployed = yearsEmployed;
    }
    public abstract int GetLevel { get; }
    public abstract string GetTitle { get; }
    public string GetFullTitle { get { return GetTitle + " " + GetLevel; } }
}

//Developer class:

 public class Developer : Employee
{
    Manager manager;

    //Manager cannot be null
    public Manager Manager
    {
        get { return manager; }
        set
        {
            if (manager != null)
            {
                manager = value;
            }
            else
                throw new ArgumentException("Manager cannot be null");
        }
    }

    //Constructor
    public Developer(int id, int yearsEmployed, string firstName,
                    string lastName, Manager manager)
        : base(id, yearsEmployed, firstName, lastName)
    {
        Console.WriteLine("manager is not null:" + manager != null); //True here
        this.Manager = manager; // manager is null here
    }

    public override int GetLevel
    {
        get { return (this.YearsEmployed + 1) / 3; }
    }

    public override string GetTitle
    {
        get { return "Developer"; }
    }
}

//Manager Class

public class Manager : Employee
{
    //Constructor
    public Manager(int id, int yearsEmployed,
                    string firstName, string lastName)
        : base(id, yearsEmployed, firstName, lastName) { }

    public override int GetLevel
    {
        get { return (YearsEmployed + 1) / 2; }
    }

    public override string GetTitle
    {
        get { return "Manager"; }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:45:27+00:00Added an answer on May 13, 2026 at 1:45 pm

    Don’t you want to say:

    if (value != null)
    

    instead of

    if (manager != null)
    

    The manager field will be initialized to null. The value keyword represents the data that is being passed to the property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is a TypeHint: PHP 5 introduces Type Hinting. Functions… May 14, 2026 at 3:51 pm
  • Editorial Team
    Editorial Team added an answer Instead of a bunch of interfaces and classes. Make a… May 14, 2026 at 3:51 pm
  • Editorial Team
    Editorial Team added an answer Have a look at nodejs http://nodejs.org/ There are a few… May 14, 2026 at 3:51 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.