The following program is Overloading or Overriding?
public class PolymorphismEx {
public int sampleMethod(int a) {
return a;
}
public String sampleMethod(int a) {
return "Is it Overloading or Overriding???";
}
}
Answers were Sorted based on User's Feedback
Answer / venkat asha reddy
it is neither overloading nor overriding. it throws method
ambiguity exception while compiling
| Is This Answer Correct ? | 16 Yes | 1 No |
Answer / kvsravindrareddy
Its kind of overriding, but the program will give compilation
error. why because Overriding cannot be possible within the
same class. or Duplicate method cannot possible within the
same class.
| Is This Answer Correct ? | 13 Yes | 5 No |
Answer / jagadish
Duplicate Method sampleMethod(int a) Error Message will display
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / hemanth
Its Neither Overloading nor overriding, Because for Overloading there should some Variation in argument list and for overriding the return type(if Primitive) should be same.
int method(int a)
{
}
String method(int a)
{
}
arguments should be different for overloading
return type should be same(if primitive) for overriding
so its improper which results in compile time error.
| Is This Answer Correct ? | 0 Yes | 0 No |
How much is a java license?
What are the main concepts of oops in java?
What is the difference between the direct buffer and non-direct buffer in java?
What is static keyword in java?
i need example for java abstraction. where we use abstraction and why we need abstraction.
1).what is the difference between below examples String s="vijay"; String s=new String("vijay");
12 Answers Mascon, Satyam, TCS,
What happens when a class is made static like if a field or member is made static it becomes class variable and is shared by all the object of the class?
How do you define a method?
Which Math method is used to calculate the absolute value of a number?
What is the use of accept () method in java?
Can you use this() and super() both in a constructor?
Can we write class inside a class in java?