There are 2 methods in a class. Both have the same method
signature except for return types. Is this overloading or
overriding or what is it?
Answer Posted / s.ramesh
public class sample
{
public void displayValue (int a, int b)
{
System.out.println("a = "+a +" b = "+b);
}
public int displayValue (int a, int b)
{
System.out.println("a+b:"+(a+b));
return (a+b);
}
public static void main(String[] args)
{
sample t = new sample();
t.displayValue(10,10);
int x = t.displayValue(20,30);
}
}
Output:
D:\Prg>javac sample.java
sample.java:8: displayValue(int,int) is already defined in
sample
public int displayValue (int a, int b)
^
sample.java:18: incompatible types
found : void
required: int
int x = t.displayValue(20,30);
^
2 errors
| Is This Answer Correct ? | 7 Yes | 0 No |
Post New Answer View All Answers
What is command line argument
What is the difference between compare and compareto in java?
How hashset works internally in java?
Explain differences between collection api and stream api?
Does java initialize arrays to zero?
What is a module function?
What is the difference between inner class and nested class?
How will you reverse a link list without using recursion?
Why is singleton class used?
Differentiate jar and war files?
What is the list interface in java programming?
What is indexof?
What is a variable declaration?
Explain notifyall() method of object class ?
What is the use of private static?