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
Who developed java?
What are the super most classes for all the streams?
What language is an assembler written in?
Is void a data type in java?
What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?
What are features of java?
Explain numeric promotion?
What is square root in java?
Why to use nested classes in java? (Or) what is the purpose of nested class in java?
Can a class be final?
Can you pass by reference in java?
What is the meaning of 3 dots in java?
Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.
Tell me about different OOPS concepts.
What is the default access specifier for variables and methods of a class?