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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:14:43+00:00 2026-06-06T02:14:43+00:00

A very simple base class: class Figure { public virtual void Draw() { Console.WriteLine(Drawing

  • 0

A very simple base class:

class Figure {
    public virtual void Draw() {
        Console.WriteLine("Drawing Figure");
    }
}

This inheriting class:

class Rectangle : Figure
{
    public int Draw()
    {
        Console.WriteLine("Drawing Rectangle");
        return 42;
    }
}

The compiler will complain that Rectangle’s “Draw” hides the Figure’s Draw, and asks me to add either a new or override keyword. Just adding new solves this:

class Rectangle : Figure
{
    new public int Draw() //added new
    {
        Console.WriteLine("Drawing Rectangle");
        return 42;
    }
}

However, Figure.Draw has a void return type, Rectangle.Draw returns an int. I am surprised different return types are allowed here… Why is that?

  • 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-06-06T02:14:45+00:00Added an answer on June 6, 2026 at 2:14 am

    Did you actually read up on the new modifier?

    Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier.

    So, you’ve hidden the version from the base class. The fact that these two methods have the same name doesn’t mean anything – they’re no more related than two methods whose names sound the same.


    Such a situation should generally be avoided, but the compiler will always know which method is to be called, and thus whether it has a return value or not. If “the” method is accessed as follows:

    Figure r = new Rectangle();
    r.Draw();
    

    Then Figures Draw method will be invoked. No return value is produced, nor expected.

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

Sidebar

Related Questions

I have a very simple MVC app at this point: Controller: public class HomeController
I have a very simple scenario, using NHibernate: one abstract base class animal; two
This very simple code: #include <iostream> using namespace std; void exec(char* option) { cout
Very simple code for test: interface Base { void interfaceTest(); static final String m
I'm working with a very simple web service that uses a base class to
Very simple example: Model: require 'inventory' class CustomerOrder < ActiveRecord::Base validates_presence_of :name validate :must_have_at_least_one_item,
I have a very simple object model with a base class Person and two
I have a simple class that provides state codes like this: public class StateProvider
I've writen a very simple Actionresult which derives from ViewResult public class FormResult :
I'm trying to define my own (very simple) exception class in Python 2.6, but

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.