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
Can constructor be inherited?
Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example
In a program, initializing an array of 100 KB is throwing an out of memory exception while there is 100 MB of memory available. Why?
How do you square a number?
What is hashmap in java?
Why local variables are stored in stack?
describe method overloading
What is the meaning of immutable regarding string?
What is entry set in java?
How arrays are stored in memory in java?
Can a java program have 2 main methods?
What is the super void?
How to sort numbers in java without array?
What is the default value of float and double datatype in java?
What is the purpose of a parameter?