using System;
namespace Oop_Inheritance_
{
class Program
{
static void Main(string[] args)
{
Animal obj=new Animal("Balto","Howl");
obj.setAnimalIdInfo(1,"Balto");
obj.getAnimalInfo();
Dog obj2 = new Dog("Hachico", "howl", "Grrrr");
obj2.Sound="Woof Woof";
obj2.setAnimalIdInfo(5, "Hachico");
obj2.getAnimalInfo();
Console.WriteLine(obj2.Name);
Console.WriteLine(obj2.Sound);
Animal sloth = new Dog("Simon", "bark", "woof");
sloth.MakeSound();
Console.ReadKey();
}
class Dog:Animal
{
string sound2;
public string Sound2 {get {return sound2;} set{sound2=value;}}
public void MakeSound()
{
Console.WriteLine("{0} says {1} and {2}",name,sound,sound2);
}
public Dog(string name = "No Name", string sound = "No Sound", string sound2 = "No Sound2"):base(name,sound)
{
Sound2 = sound2;
}
}
class Animal
{
protected string name;
protected string sound;
protected AnimalIDInfo objid = new AnimalIDInfo();
public void setAnimalIdInfo(int id, string own)
{
objid.IDNum = id;
objid.Owner = own;
}
public void getAnimalInfo()
{
Console.WriteLine("{0} has id:{1} and is owned by {2} ", name, objid.IDNum, objid.Owner);
}
public Animal()
: this("No Name", "No Sound") { }
public Animal(string n)
: this(n, "No Sound") { }
public Animal(string n, string s)
{
Name = n;
Sound = s;
}
public string Sound
{
get { return sound;}
set
{
sound = value;
}
}
public virtual void MakeSound()
{
Console.WriteLine("{0} says {1}", name, sound);
}
public string Name
{
get { return name; }
set
{
int flag = 0;
foreach (char a in value)
{
if (!char.IsLetter(a))
{
Console.WriteLine("Name has number in it");
flag = 1;
break;
}
}
if (flag == 0)
{
name = value;
}
}
}
}
}
}
namespace Oop_Inheritance_
{
class Program
{
static void Main(string[] args)
{
Animal obj=new Animal("Balto","Howl");
obj.setAnimalIdInfo(1,"Balto");
obj.getAnimalInfo();
Dog obj2 = new Dog("Hachico", "howl", "Grrrr");
obj2.Sound="Woof Woof";
obj2.setAnimalIdInfo(5, "Hachico");
obj2.getAnimalInfo();
Console.WriteLine(obj2.Name);
Console.WriteLine(obj2.Sound);
Animal sloth = new Dog("Simon", "bark", "woof");
sloth.MakeSound();
Console.ReadKey();
}
class Dog:Animal
{
string sound2;
public string Sound2 {get {return sound2;} set{sound2=value;}}
public void MakeSound()
{
Console.WriteLine("{0} says {1} and {2}",name,sound,sound2);
}
public Dog(string name = "No Name", string sound = "No Sound", string sound2 = "No Sound2"):base(name,sound)
{
Sound2 = sound2;
}
}
class Animal
{
protected string name;
protected string sound;
protected AnimalIDInfo objid = new AnimalIDInfo();
public void setAnimalIdInfo(int id, string own)
{
objid.IDNum = id;
objid.Owner = own;
}
public void getAnimalInfo()
{
Console.WriteLine("{0} has id:{1} and is owned by {2} ", name, objid.IDNum, objid.Owner);
}
public Animal()
: this("No Name", "No Sound") { }
public Animal(string n)
: this(n, "No Sound") { }
public Animal(string n, string s)
{
Name = n;
Sound = s;
}
public string Sound
{
get { return sound;}
set
{
sound = value;
}
}
public virtual void MakeSound()
{
Console.WriteLine("{0} says {1}", name, sound);
}
public string Name
{
get { return name; }
set
{
int flag = 0;
foreach (char a in value)
{
if (!char.IsLetter(a))
{
Console.WriteLine("Name has number in it");
flag = 1;
break;
}
}
if (flag == 0)
{
name = value;
}
}
}
}
}
}
Comments
Post a Comment