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
Define an applet in java?
What is the difference between a local variable and an instance variable?
How many types of methods are there?
List the different types of classloaders in java.
Explain about interthread communication and how it takes place in java?
What comes to mind when someone mentions a shallow copy in java?
What is toarray method in java?
What is difference between fail-fast and fail-safe?
Does every java program need a main?
What are the library functions in java?
What is the default size of arraylist in java?
How do you convert string to int in java?
Can you make a constructor final?
What is Java Shutdown Hook?
How do you declare a string variable?