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
Is age a discrete variable?
What is the static import?
What is the base class of all classes?
Differentiate between vector and array list.
What is a class variable?
What are the different tags provided in jstl?
What is the gregoriancalendar class in java programming?
explain multi-threading in java?
What are the differences between Java 1.0 and Java 2.0?
Who is founder of java?
What is off heap memory?
What is a method in coding?
What is bitwise complement?
What is an example of procedure?
Explain the concept of hashtables?