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???";
}
}

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Wha is the output from system.out.println(“hello”+null); ?

696


What are the four integer types supported by java?

566


Does importing a package imports its sub-packages as well in java?

554


Explain about exception propagation?

587


Is array size fixed in java?

542






Which methods cannot be overridden in java?

539


Is ++ operator thread-safe in java?

636


what is the major difference between linkedlist and arraylist in java?

551


What is byte [] in java?

538


Can a constructor be made final?

666


Write a program to search a number in the given list of numbers.

631


difference between byte stream class and character stream class?

4085


Differentiate between the constructors and methods in java?

511


When do you get classcastexception?

558


Where are register variables stored?

593