-
September 24th, 2013, 01:35 PM
#1
Instance Problem
Hey all, I'm fairly new to C# and come from a Java background. In this project I cant seem to instantiate an object of the class Dog from the TestAnimal class in a separate file. Can anyone point me in the right direction?
Thanks in advance!
Dog Class
Code:
using System;
namespace Application
{
public class Animal
{
// Local variables
private string name;
private int age;
private string talk;
// Animal Constructor
public Animal(string name, int age, string talk)
{
setName(name);
setAge(age);
setTalk(talk);
}
// Setters
public void setName (string name)
{
this.name = name;
}
public void setAge (int age)
{
this.age = age;
}
public void setTalk (string talk)
{
this.talk = talk;
}
// Getters
public string getName()
{
return name;
}
public int getAge()
{
return age;
}
public string getTalk ()
{
return talk;
}
}
// Dog inherits from Animal
public class Dog : Animal
{
public Dog (string name, int age, string talk) : base(name,age,talk)
{
}
public void dogDetails()
{
Console.WriteLine("Name: " + getName() + "\n\nAge: " + getAge () + "\n\nRex: " + getTalk());
}
}
}
TestAnimal Class
Code:
using System;
namespace Application
{
public class TestAnimal
{
public static void Main(string[] args)
{
Dog d = new Dog("Rex", 3, "BARKS!!"); // error saying namespace Dog cannot be found.
d.dogDetails();
}
}
}
-
September 25th, 2013, 10:37 AM
#2
Re: Instance Problem
Isn't 'Application' already a namespace used by VisualStudio?
-
September 25th, 2013, 12:25 PM
#3
Re: Instance Problem
Sorry I should have stated that I am coding on a Mac and using Mono Develop as my IDE for C#. And "Application" was the namespace generated automatically for me by Mono Develop.
-
September 26th, 2013, 04:38 PM
#4
Re: Instance Problem
Don't know how the Mono environment works, but is the file where the Animal and Dog classes are defined included in your project? In Visual Studio, when you create a new class it automatically includes the file in your project. Make sure that is the case in your environment.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|