what is difference between method overloading & method
overridding with example?

Answer Posted / sirisha

overridding:
same method name and same signature.
import java.io.*;
class sum
{
int a=10,b=15;
void sum()
{
int sum=a+b;
System.out.println("sum is:"+sum);
}
}
class sum1 extends sum
{
int c=20;
void sum()
{
int sum1=a+b+c;
System.out.println("sum1 is:"+sum1);
}
}
class override{
public static void main(String[] arg){
sum s=new sum();
s.sum();
sum1 s1=new sum1();
s1.sum();
}
}

over loading:
method name same but different signature.
class sum{
void add(int a,int b){
}
class sum{
void add(string s1,string s2){
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should I use a singleton?

763


What is dynamic array in java?

737


What does singleton mean in java?

713


Can list be final in java?

684


How can you read an integer value from the keyword when the application is runtime in java? example?

856


Explain about anonymous inner classes in java?

775


Which class contains a method: cloneable or object?

751


What are the Main functions of Java?

813


What is the final keyword?

756


Is arraylist zero based?

759


Can we extend singleton class in java?

742


What is null mean in java?

835


Does treeset allow null in java?

701


When do you get classcastexception?

774


What are the differences between forwarding () method and sendredirect() methods?

825