Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Cat
- {
- // Fields
- private string name;
- private string color;
- // Properties
- public string Name
- {
- get
- {
- return this.name;
- }
- set
- {
- this.name = value;
- }
- }
- public string Color
- {
- get
- {
- return this.color;
- }
- set
- {
- this.color = value;
- }
- }
- // Default (parameterless) constructor
- public Cat()
- {
- this.name = "Unnamed";
- this.color = "gray";
- }
- // Constructor with parameters
- public Cat(string name, string color)
- {
- this.name = name;
- this.color = color;
- }
- // Method
- public void SayMiau()
- {
- Console.WriteLine("Cat {0} said: Miauuuuuu!", name);
- }
- }
- class Program
- {
- static void Main()
- {
- Cat someCat = new Cat();
- someCat.SayMiau();
- Console.WriteLine("The color of cat {0} is {1}", someCat.Name,someCat.Color);
- Console.WriteLine();
- Cat myCat = new Cat("Johnny", "brown");
- myCat.SayMiau();
- Console.WriteLine("The color of cat {0} is {1}", myCat.Name, myCat.Color);
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement