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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:01:37+00:00 2026-06-17T18:01:37+00:00

I am learning OOP and have a question about what is exactly happening with

  • 0

I am learning OOP and have a question about what is exactly happening with the code below.

I have the classic Dog Animal example going. Dog inherits Animal.

public class Animal
{
    public string Name { get; set; }

    public virtual string Speak()
    {
        return "Animal Speak";
    }

    public string Hungry()
    {
        return this.Speak();
    }
}


public class Dog : Animal
{
    public override string Speak()
    {
        return "Dog Speak";
    }

    public string Fetch()
    {
        return "Fetch";
    }
}

Both questions are based on this assignment: Animal a = new Dog();

  1. What is actually happening when I declare an Animal and set it to a Dog reference. Is there a specific term for this?
  2. When I call a.Hungry(), the output is “Dog Speak.” If the output is “Dog Speak”, why can I not call a.Fetch()? What is the term for what’s happening here?

Any help and further reading on the particular topic would be greatly appreciated.

  • 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-17T18:01:38+00:00Added an answer on June 17, 2026 at 6:01 pm
    1. This is an “upcast”. In C# there is an implicit conversion from any type to any of it’s base types, so you don’t need to do anything to treat a Dog as if it were an Animal. (Thanks to Matt Burland for reminding me that this is the appropriate term.)
    2. Because the type of the variable is Animal, and as such you can only access members that the compiler knows an Animal can access, i.e. Speak and Hungry. It doesn’t know that the Animal is a Dog, so it can’t call Fetch. The variable would need to be of type Dog for you to be able to call Fetch on it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning php and OOP programming here. I have below working code I am
I just started learning Objective-C and OOP ... so I have very stupid question
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I have been recently learning some OOP PHP and seem to have run into
I'm learning Java and OOP, and have been doing the problems at Project Euler
I'm learning more about javascript OOP by rolling my own console.log variant with some
Choices I am learning OOP PHP, but some things are really confusing. I have
I'm not exactly sure how to ask this because I am just learning OOP
Ok I am trying to start really learning OOP style in PHP. I have
I have the following problem (just learning OOP style C++): I have 3 classes:

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.