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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:45:03+00:00 2026-05-29T20:45:03+00:00

I am working on an assignment with polymorphism and have followed online tutorials that

  • 0

I am working on an assignment with polymorphism and have followed online tutorials that I have found on polymorphism in c#. My first questions is am I using it correctly. I have a parent class called gameCreature and two child classes called agileCreature and predatorCreature. I put in virtual and override in the classes. When I used a loop to print out all the objects everything looked ok. Here is the code

     gameCreature[] _creature = new gameCreature[sizeBig];
        agileCreature[] _agile = new agileCreature[size];
        predatorCreature[] _predator = new predatorCreature[size];
        for (int i = 0; i < size; i++)
        {
            _creature[i] = new gameCreature();
        }
        for (int i = size; i < sizeMid; i++)
        {
            _creature[i] = new agileCreature();
        }
        for (int i = size * 2; i < sizeBig; i++)
        {
            _creature[i] = new predatorCreature();
        }

Also, if that is correct. I am running into another problem. I am trying to call a method called consumeCreature that is only in the predatorCreature, but cannot call it. I think this is because there is no consumeCreature method in gameCreature. Besides adding a consumeCreature method to the parent, is there another way to call consumeCreature method? Here is the code for that.

 _creature[_creatureNum].consumeCreature(_creature[ate]);

Can I add something to it, so it knows to use consumeCreature in predatorCreature.

  • 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-29T20:45:04+00:00Added an answer on May 29, 2026 at 8:45 pm

    If you’re sure that _creature[_creatureNum] is predatorCreature, you can do it in the following way: (_creature[_creatureNum] as predatorCreature).consumeCreature(_creature[ate]).

    Could you please provide a bit more background (namely, where do you get this _creatureNum and why do you need the array of all creatures)?

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

Sidebar

Related Questions

I'm working on an assignment that is telling me to assume that I have
Currently I'm working on an assignment and using C++ for the first time. I'm
I'm working on a class assignment that started small, so I had it all
I am working on a C++ assignment for class that wants me to overload
Working on my assignment for Java and I have created a class called Triangle.
I am working on an assignment that uses a base class bankAccount and two
I am working on an assignment that introduces me to operator overloading. I have
I'm working on an assignment. An online order system using EJB 3.0. im using
I am working on an assignment for a college assembly class. We are using
I'm working on an assignment in my beginner Javascript class that involves an element

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.