Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Object-Oriented Programming Instantiation

William Steele
William Steele
1,739 Points

Instantiation

How do I declare the frog class and give it a name at the same time, tried doing it the way it showed in video but said it was wrong and have been messing around but not finding anything

Program.cs
namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {            
            new Frog == Frog 'mike'
        }
    }
}
Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog{}
}

2 Answers

Antonio De Rose
Antonio De Rose
20,882 Points
namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {            
            new Frog == Frog 'mike'
            //when you want to instantiate a class
            //class instancevariable = new kewyword class(), this will lead to the below
            //questions asks you to use the mike word for the instance variable
            //Frog mike = new Frog();

        }
    }
}

William,

I had the same issue as you, and found the answer by removing a sneaky space I had between my class Frog and the (); , after I defined the new variable.

e.g. this was wrong: Frog mike = new Frog ();

but I removed the final space and Treehouse let me have it. My initial method was still valid, but not 100% grammatically/typographically correct.

:)