Wednesday, July 8, 2009

Tip of the day

Calling classes with out Instance

1) Creating static objects.
2) Making the modifier as a public in the base class method. then inherit in to the derived class. after call that method directly.
3) After inheriting base class to derived class. using base key we can get the all the methods.

Example.

All programmers knows the first option. let me explain another two scenoria with the appropriate example.


public class classA
{
public classA()
{

}
public string A()
{
return "s";
}
}

public class classB: classA
{
public string callWithoutInstance()
{
//Inherite the base class then directly call the public method
return A();
}
public string callWithoutInstanceBase()
{
//Inherite the base class then call the public method through base class.
return base.A();
}
}