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

Define an applet in java?

627


What is the difference between a local variable and an instance variable?

544


How many types of methods are there?

542


List the different types of classloaders in java.

498


Explain about interthread communication and how it takes place in java?

538






What comes to mind when someone mentions a shallow copy in java?

649


What is toarray method in java?

553


What is difference between fail-fast and fail-safe?

582


Does every java program need a main?

534


What are the library functions in java?

542


What is the default size of arraylist in java?

498


How do you convert string to int in java?

554


Can you make a constructor final?

573


What is Java Shutdown Hook?

608


How do you declare a string variable?

512