Hi
My base class tostring method isn't printing to the console, the child class one is though
It prints out favorite toy and the sound method but nothing else, any ideas?
thanks
My base class tostring method isn't printing to the console, the child class one is though
Code:
static void Main(string[] args)
{
Cat C = new Cat("Fluffy",4,"Tabby","Ginger","Mouse");
Console.WriteLine(value: C.ToString());
C.sound();
}
Code:
public abstract class Animal
{
private String name;
private int age;
private String breed;
private String furColor;
public Animal(String name,int age,String breed,String furColor)
{
this.name = name;
this.age = age;
this.breed = breed;
this.furColor = furColor;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return this.age;
}
public void setBreed(String breed)
{
this.breed = breed;
}
public String getBreed()
{
return this.breed;
}
public void setFurColor(String furColor)
{
this.furColor = furColor;
}
public String getFurColor()
{
return this.furColor;
}
public abstract void sound();
public string ToStirng()
{
return ("Name: " + getName()
+"\n"
+"Age: " + getAge()
+"\n"
+"Breed: " + getBreed()
+"\n"
+"Fur Color: " + getFurColor());
}
}
Code:
public class Cat : Animal
{
private String favoriteToy;
public Cat(String name,int age,String breed,String furColor,String favoriteToy):base(name,age,breed,furColor){
this.favoriteToy = favoriteToy;
}
public void setFavoriteToy(String favoriteToy)
{
this.favoriteToy = favoriteToy;
}
public String getFavoriteToy()
{
return this.favoriteToy;
}
public override void sound()
{
Console.WriteLine( getName() + " is a beautiful cat, he is " + getAge() + " and he likes to Meow.");
}
public override string ToString() => (base.ToString() +
"\n"
+ "Favorite Toy: " + getFavoriteToy());
}
It prints out favorite toy and the sound method but nothing else, any ideas?
thanks