What is the Difference between Overriding and overloading?
Answers were Sorted based on User's Feedback
Answer / venkatreddy
overriding:method name and signature are must be same.
overloading: functionality that enables you to define tow or more methods with the same name but with different signatures within the class the methods that share the same name ,but have different signature are called overloaded methods.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / neeraj sahu
Overloading : It is a feature of OOPs , by that we can
achieve run time polymorphism. To declare it we need the
same method name but different argument or different types
of argument.
Overriding : It is a feature of OOPs, By that we can achieve
compile time polymorphism.To declare it we need the same
method name and same types and same number of argument but
in different class.
Is This Answer Correct ? | 5 Yes | 5 No |
Answer / aparna murthy
overloading is the ability to define several methods with
the same name ,provided each method has a different signature.
example:--
class shape
{
public void area(double r)
{
console.writeline("Area of circle :"+(3.14*r*r));
}
public void area(double l,double b)
{
console.writeline("Area of rectangle :"+(l*b));
}
public void area(int b,int h)
{
console.writeline("Area of rectangle :"+(0.5*b*h));
}
}
class program
{
static void main(string[]args)
{
shape s=new shape()
s.area(7,6)
s.area(22,11);
s.area(12,20);
console.read();
}
}
try this example.....
signature of a method is the datatype of the
parameters,number of parameters and the sequence in which
they are passed to the function .
overriding:---
In method overriding method have same names same signatures
same return types but in different scopes(classes) in
hierarchy .c# uses virtual and override keywords to define
method overriding .Method overriding enables object to
resolve method invocation at runtime.we call it late binding
behavior of object.
1.An override declaration cannot change the accesibility of
vitual method .Both the override method and the virtual
method must have the same access level modifier.
2.Methods which are to be overriden in the subsequent
derived class are made virtual or abstract in base class.
example:--
class employee
{
public virtual double calculatesalary()
{
return basic+hra+da;
}
}
class manager:employee
{
public override double calculatesalary()
{
return basic+hra+da+allowances;
}
}
static void main(string[] args)
{
employee mgr=new manager();
double salary=mgr.calculatesalary();
console.writeline(salary);
console.readline();
}
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / veena
overloading:-
-------------- function name same and parameters in the functions are different
class function
{
public string find_big(int a, int b)
{
//source code
}
public string find_big(float a, float b)
{
//source code
}
function overridding:-
------------------------in this function name same and the difference is inherits the 2nd class(derived class) from 1st class(base class)and
use the virtual to base class and override to derived class
virtual:-
----------
if we use virtual then the function calls once. it's c++ style
eg:-
class one
{
public virtual void display()
{
System.Console.WriteLine("one:display");
}
}
class two : one
{
public override void display()
{
System.Console.WriteLine("two:display");
}
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / mercy s
Method Overloading: It is the compile time polymorphism.
It has same method name but different parameters with in the
class
Method Overriding: It is the run time polymorphism. It has
same method name and same parameters but with in the name
space.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dhaval soni
Hi, friend My Name is Dhaval Soni
Thanks for giving me a chance for writing.
bye
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / jaya v. parmar
overloading:- Method name are same but argument are different.
overriding:- method,return type,argument are same but derived
class are different.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / m.usama
Overloading:
1.Methods having same name with different number of
parameters or different data type with same number of
parameter..
2. It is possible that overloading in inheritance..
Overriding:
1.The method in the derived class the has the
same name and same parameters in the base class and it
changes the behavior or functionality of the method in the
derived class,with overriding single reference of method is
created in memory of override function ..
2. Must be public.
3. possible in inheritance.
Is This Answer Correct ? | 2 Yes | 3 No |
Answer / m.j
overloading:
argument list must diff.
return type can b dif.
overridding:
args list same
Is This Answer Correct ? | 1 Yes | 3 No |
Can we use a crystal report into a another crystal report
hi dear ? MY problem is that i m developing software for Library. and i want to connect a third party software with my VB.net program in order to calculate DDC number.I dont know how to do this if any body can help me please?
What is the advantages of VB.NET?
What is econo-jit?
Explain the difference between vb.net and c#, related to oops concepts?
Explain public assembly?
Name the two main parts of .net?
What is writeline in vb.net?
Name and explain some of the exclusive features which are present in vb?
What do you mean by serialization?
What is the use of console application?
if user enters 1 or 2 or any other number in digit format in next textbox it should show the answer in word reading like if enters 12 answer should be twelve