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

  • Home
  • SEARCH
  • 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 6188405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:13:32+00:00 2026-05-24T02:13:32+00:00

I want to create a Creature class who will be the parent class of

  • 0

I want to create a Creature class who will be the parent class of all living creatures such as humans.

So I wrote a Creature class and a Human class with proper heritage.

As I want all the creatures to do a couple a things and I don’t want to make a default function for each behaviour in the Creature class, I created a CreatureInterface that is implemented by all the living creatures.

This is the code :

creature.vala :

// Different kind of genders
public enum GENDER
{
    MALE,
    FEMALE
}

// Different kind of moods
public enum MOOD
{
    HAPPY,
    SAD,
    NEUTRAL
}

// Different kind of body size for basic physical representation
public enum BODY_SIZE
{
    STANDARD,
    TALL,
    SMALL
}

// Different kind of body weight for basic physical representation
public enum BODY_WEIGHT
{
    STANDARD,
    FAT,
    THICK
}

public class Creature
{

    // Physic

    protected BODY_SIZE _body_size = BODY_SIZE.STANDARD;
    protected BODY_WEIGHT _body_weight = BODY_WEIGHT.STANDARD;

    // Mental

    protected MOOD _mood = MOOD.NEUTRAL;

    // Social

    protected GENDER _gender = GENDER.MALE;
    protected string _name = "";
    protected string _family_name = "";

    protected Creature _mother = null;
    protected Creature _father = null;
    protected List<Creature> _children = null;

    // Reproduction

    protected int _number_of_babies_by_pregnancy = 0;
    protected int _uncommon_number_of_babies_by_pregnancy = 0;
    protected int _very_uncommon_number_of_babies_by_pregnancy = 0;
    protected int _pregnancy_duration = 0; // In days

    public Creature ()
        {

            if ( Random.int_range(0, 2) == 1.0 )
            {
                this._gender = GENDER.MALE;
            }
            else
            {
                this._gender = GENDER.FEMALE;
            }

        }

    ~Creature ()
        {
            stdout.printf( "I'm dying" );
        }



}

public interface CreatureInterface
{

    // Generate a name with specific rules for species
    protected abstract void generateName();

    // Get a goal for the next action
    public abstract void getAGoal();

}

human.vala :

public class Human : Creature, CreatureInterface
{

    public Human ()
    {

        // Get a name for our new human being
        this.generateName();

        // Social

        string name = this._name;
        string family_name = this._family_name;

        if ( this._gender == GENDER.MALE )
        {
            stdout.printf( @"Say \"hello\" to $family_name $name, a human male baby.\n" );
        }
        else
        {
            stdout.printf( @"Say \"hello\" to $family_name $name, a human female baby.\n" );
        }

        // Reproduction

        this._number_of_babies_by_pregnancy = 1;
        this._uncommon_number_of_babies_by_pregnancy = 2;
        this._very_uncommon_number_of_babies_by_pregnancy = 3;
        this._pregnancy_duration = 275; // 9 months

    }

    /**
     * Destructor
     */
    ~Human ()
    {
    }

    public void generateName()
    {

        if ( this._gender == GENDER.MALE )
        {
            this._name = "Jhon";
        }
        else
        {
            this._name = "Jane";
        }

        this._family_name = "Doe";

    }

    public void getAGoal()
    {
        stdout.printf("I need a goal...");
    }

}

main.vala :

public class Main
{
    public static int main (string[] args)
        {

            stdout.printf( "Genesis\n" );

            Creature john_doe = new Human();
            john_doe.getAGoal();

            return 0;
        }
}

Now when I compile, I have the following error that I don’t understand :

./src/main.vala:9.4-9.20: error: The name `getAGoal' does not exist in the con
text of `Creature?'                                                          
                        john_doe.getAGoal();
                        ^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
make: *** [build] Erreur 1

getAGoal as been implemented in human and is public.

So, why is it unreachable ?

  • 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-24T02:13:34+00:00Added an answer on May 24, 2026 at 2:13 am

    It’s CreatureInterface that has that method, not Creature.

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

Sidebar

Related Questions

I want to create a city filled with virtual creatures. Say like Sim City,
I want create a DataSet class which is basically a list of samples. But
I want create constructor that will take one or more integers and save it
I want create object from Canvas3D class(in java) but my Compiler doesn't have this
I want create a new <li> component, then add href, class, etc.. and finally
I want create a ModelForm class where model is a parameter passed from the
I want create a tarball that when extracted the file(s) will be placed at
I want create some type of ASP.NET (C# 2.0) Metrics class to help monitor
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert

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.