Overloading: is the mechanism to have more than one 
method with same name but with different signature (parameters). A 
method can be overloaded on the basis of following properties
Overriding: Overriding can be done in derived class, an override method provides a new implementation of a method inherited from parent class.
To override a method in base (parent) class it must be
- Have different number of parameter
- Having same number of parameters but of different type
- Having same number and type of parameters but in different orders
- Different return type
- Different access modifier
- Normal and optional parameters
public List<Customer> FindCustomer(String customer_name)
{
  // your code
}
public List<Customer> FindCustomer(Int32 customer_Id)
{
  // your code
}
public List<Customer> FindCustomer(String customer_name, String city)
{
  // your code
}
public List<Customer> FindCustomer(String customer_name, Int32 customer_Id)
{
  // your code
}
public List<Customer> FindCustomer(String customer_name, String city, String zip)
{
  // your code
}
public List<Customer> FindCustomer(String customer_name)
{
  // your code
}
public Customer FindCustomer(String customer_name)
{
  // your code
}
public List<Customer> FindCustomer(String customer_name)
{
  // your code
}
private List<Customer> FindCustomer(String customer_name)
{
  // your code
}
public List<Customer> FindCustomer(String customer_name)
{
  // your code
}
private List<Customer> FindCustomer(String customer_name = String.Empty)
{
  // your code
}
Overriding: Overriding can be done in derived class, an override method provides a new implementation of a method inherited from parent class.
To override a method in base (parent) class it must be
- virtual
- abstract
- override
- non-virtual
- static
- new
- static
- virtual
- abstract
public class Square {
  public double side;
  // Constructor:
  public Square(double side) 
  {  this.side = x; }
  public virtual double Area() 
  {   return side  * side ;  }
}
class Cube: Square {
   // Constructor:
   public Cube(double side): base(x)    { }
   // Calling the Area base method:
   public override double Area() 
   { return (6*(base.Area())); }
}
- Overloading can be done in same class
- Overriding can be done in parent and derived class
- Overloading in used when we need same method in same class with different parameters
- Overriding is used when we need to redefine a method that has already been defined in parent class (using the exact same signature
- Overloading is resolved at compile time
- Overriding is resolved at run time
 
No comments:
Post a Comment