Type of Overloading
1) Function Overloading
2) Operator Overloading
Difference between overloading & overridding
Overloading is used when we want same name and different parmeters.
Overriding is used when we want to replace the method
In Overloading Name of the function is same but the arguments are different.
In Overriding a local function can override the global function.
overloading is mainly for operators and overriding is for functions
Example(Overloading)
public int add(int a, int b, int c)
{
return a + b + c;
}
public int add(int a, int b)
{
return a + b;
}
Wednesday, April 22, 2009
Abstract Class
Where can we use abstract modifier?
The abstract modifier is used with following:
1) classes
2) methods
3) properties
4) indexers
5) events
Example of Abstract class
The abstract modifier is used with following:
1) classes
2) methods
3) properties
4) indexers
5) events
Example of Abstract class
abstract class ShapesClass
{
abstract public int Area();
}
class Square : ShapesClass
{
int side = 0;
public Square(int n)
{
side = n;
}
// Area method is required to avoid
// a compile-time error.
public override int Area()
{
return side * side;
}
static void Main()
{
Square sq = new Square(12);
Console.WriteLine("Area of the square = {0}", sq.Area());
}
interface I
{
void M();
}
abstract class C : I
{
public abstract void M();
}
}
Benefits for using Abstract class.
The real benefit of using abstract classes is that the extended classes
can implement the abstract methods in their own way.
Subscribe to:
Posts (Atom)