Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Collar
- {
- // Static field, holding the current sequence value
- private int c = 0;
- // Intentionally deny instantiation of this class
- public Collar()
- {
- }
- }
- class Dog
- {
- private string name;
- private int age;
- private double length;
- private Collar collar;// Field name
- // No parameters
- public Dog()
- {
- this.name = "Sharo";
- this.age = 1;
- this.length = 0.3;
- this.collar = new Collar();
- }
- // One parameter
- public Dog(string name)
- {
- this.name = name;
- this.age = 1;
- this.length = 0.3;
- this.collar = new Collar();
- }
- // Two parameters
- public Dog(string name, int age)
- {
- this.name = name;
- this.age = age;
- this.length = 0.3;
- this.collar = new Collar();
- }
- // Three parameters
- public Dog(string name, int age, double length)
- {
- this.name = name;
- this.age = age;
- this.length = length;
- this.collar = new Collar();
- }
- // Four parameters
- public Dog(string name, int age, double length, Collar collar)
- {
- this.name = name;
- this.age = age;
- this.length = length;
- this.collar = collar;
- }
- static void Main()
- {
- Dog myDog = new Dog("Bobi", 2, 0.4); // Three parameters Constructors
- Console.WriteLine("My dog " + myDog.name +
- " is " + myDog.age + " year(s) old. " +
- " and it has length: " + myDog.length + " m");
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment