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 7005267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:19:47+00:00 2026-05-27T21:19:47+00:00

What’s wrong with this set of code? I have errors and I can’t find

  • 0

What’s wrong with this set of code? I have errors and I can’t find out what’s wrong with it. Below is the logic for what I am trying to do. Can someone help me solve this?

CustNum says that it’s hiding an inherited member and it’s saying an error for the Convert.ToInt32 line and the new Customer() method does not work.

using System;
public class DebugEight01
{
    public static void main()
    {
        Customer aRegularCustomer = new Customer();
        FrequentCustomer aFrequentCustomer = new Customer(); // I have an error here. 
        aRegularCustomer.CustNum = 2514;
        aRegularCustomer.CustBalance = 765.00;
        aFrequentCustomer.CustNum = 5719;
        aFrequentCustomer.CustBalance = 2500.00;
        aFrequentCustomer.DiscountRate = 0.15;   //15 % 
        Console.WriteLine("\naRegularCustomer #{0} owes {1}",
           aRegularCustomer.CustNum,
           aRegularCustomer.CustBalance = Convert.ToInt32; // I have an error here
        Console.WriteLine("\naFrequentCustomer #{0} would owe {1} without the discount",
           aFrequentCustomer.CustNum,
           aFrequentCustomer.CustBalance.ToString("C2"));
        double newBal = (1 - aFrequentCustomer.DiscountRate) *
           aFrequentCustomer.CustBalance;
        Console.WriteLine("...with {0} discount, customer owes {1}",
           aFrequentCustomer.DiscountRate.ToString("P"), newBal.ToString("C"));
    }
}
public class Customer
{
    private int custNum;
    private double custBalance;
    public int CustNum
    {
        get
        {
            return custNum;
        }
        set
        {
            custNum = value;
        }
    }
    public double CustBalance
    {
        get
        {
            return custBalance;
        }
        set
        {
            CustBalance = value;
        }
    }
}
class FrequentCustomer : Customer
{
    private double discountRate;
    public double DiscountRate
    {
        get
        {
            return discountRate;
        }
        set
        {
            discountRate = value;
        }
    }
    public int CustNum // I have an error here, it's hiding inherited member?
    {
        get
        {
            return base.CustNum;
        }
        set
        {
            CustNum = value;
        }
    }
}
  • 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-27T21:19:47+00:00Added an answer on May 27, 2026 at 9:19 pm

    When you are working with classes and inheritance, there are some rules that are applied when you instantiate variables.

    If your inheritance tree is something like this

    class Object
    + class Customer
    + class FrequentCustomer

    If you declare a variable of type Object on the right side of the declaration it can take any type that is further down the inheritance tree. This means, it your variable is of type FrequentCustomer it has to be assigned an instance of FrequentCustomer only. If it’s of type Customer then it can take both Customer and FrequentCustomer and so on. All classes inherit the type object, which is why I added it to the inheritance tree.
    The following are all valid declarations.

    object c = new Customer();
    object c = new FrequesntCustomer();
    Customer c = new Customer();
    Customer c = new FequentCustomer();
    FrequentCustomer c = new FrequentCustomer();
    

    This is where why your first compile error occurs.

    Second error is because you are using the Convert.ToInt32() method incorrectly. The correct syntax is

    Console.WriteLine("\naRegularCustomer #{0} owes {1}",
           aRegularCustomer.CustNum,
           Convert.ToInt32(aRegularCustomer.CustBalance)); // im having a error here
    

    Your third error is not an error, but a warning only. The class FrequentCustomer already has the properties from Customer inherited, even though you haven’t specified them explicitly. This means, that you don’t need to specify the propert CustNum in the FrequentCustomer class, it already had it inherited. However, if for some reason you need to add the property (because for example it has different implementation that his parent class), then you need to add the keyword new on the property like this:

    public new int CustNum
    {
        get
        {
            return base.CustNum;
        }
        set
        {
            CustNum = value;
        }
    }
    

    If you don’t do this, this will be done automatically (hiding inherited member), but you will get a warning about it.

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

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.