using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespace App8
{
classProgram
{
publicint x=9;
Program()
{
Console.WriteLine("Simple Constructor");
}
static Program()
{
Console.WriteLine("Static Constructor");
}
Program(int x)
{
this.x = x;
Console.WriteLine(x*x);
}
Program(intx,int y)
{
Console.WriteLine(x+y);
}
Program(Program p)
{
x = p.x;
}
staticvoid Main(string[] args)
{
Program p1, p2, p3, p4;
Method();
p1 = newProgram();
p2 = newProgram(2);
p3 = newProgram(4,8);
p4 = newProgram(p2);
Console.WriteLine(p4.x);
Console.ReadLine();
}
staticvoid Method()
{
Console.WriteLine("Static method.");
}
}
}
|
OUTPUT: Static Constructor Static method. Simple Constructor 4 12 2 |
No comments:
Post a Comment