Share on Google+Share on Google+

SCJP Module-4 Question-4

Advertisement
This program given below checks you knowledge of float in Java and shows how the values can be returned in float.

Given the following sample code:

class Example4{
public float Twin(float a, float b) {
return 0F;
}
public int Twin(int a, int b) {
return 0;
} }

Is the above sample code correct ?choose the correct reason  :

1. Incorrect , methods can't have the same name.

2. Incorrect , methods must not use same number of arguments.

3.Correct, method overloading is used.

4.Incorrect ,must use in different class.

Answer :

(3)

Explanation :

In method overloading ,same name methods can have same number of arguments but type must be differnt.

Advertisements

Posted on: July 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.