Saturday, November 7, 2009

SAMPLE PROGRAM for CONSTRUCTOR

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication12
{
class Super
{
public int height;
public int Widith;
public Super(int x, int y)
{
height = x;
Widith = y;
}
public int Display()
{
return (height * Widith);
}
}
class test
{
public static void Main()
{
Super s = new Super(10, 20);
int i = s.Display();
Console.WriteLine("Multiplication is :" + i);
Console.ReadLine();
}


}
}


Here public Super(int x, int y) is a method but the class name is also super therefor it is called as constructor.

No comments:

Post a Comment