L ESSONS
L ESSONS
are different.
class Car {
Car() {
...
}
Car(string brand) {
...
}
Notice that,
}
EXAMPLE OF CONSTRUCT OVERLOAD
using System;
namespace ConstructorOverload {
class Car {
Console.WriteLine();
Console.ReadLine();
}
}
}
Output
Car constructor
// Class Declaration
public class Dog {
// Instance Variables
String name;
String breed;
int age;
String color;
// Property 1
public String GetName()
{
return name;
}
// Property 2
public String GetBreed()
{
return breed;
}
// Property 3
public int GetAge()
{
return age;
}
// Property 4
public String GetColor()
{
return color;
}
// Method 1
public String ToString()
{
return ("Hi my name is " + this.GetName()
+ ".\nMy breed, age and color are " + this.GetBreed()
+ ", " + this.GetAge() + ", " + this.GetColor());
}
// Main Method
public static void Main(String[] args)
{
// Creating object
Dog tuffy = new Dog("tuffy", "papillon", 5, "white");
Console.WriteLine(tuffy.ToString());
}
}
Output
Hi my name is tuffy.
My breed, age and color are papillon, 5, white
// C# Program to illustrate calling of
// parameterized constructor.
using System;
namespace ParameterizedConstructorExample {
class Geek {
// Main Method
public static void Main()
{