Computer Applications
Which of the following pairs of methods will cause a compile-time error due to incorrect method overloading?
- void test(int a, int b) and void test(double a, double b)
- void test(int a, double b) and void test(double a, int b)
- void test(int a, double b) and void test(int a)
- void test(int a) and int test(int a)
Answer
void test(int a) and int test(int a)
Reason — In Java, method overloading depends on the method's name and its parameter list (number or type of parameters). The return type alone is not considered for method overloading. So, void test(int a) and int test(int a) have the same name and same parameter list, which causes a compile-time error because they differ only in return type, not in parameters.
Related Questions
The index(subscript) of the last element of an array ar[] is:
- ar.length()
- ar[].length
- ar.length() – 1
- ar.length – 1
Assertion (A): A clock is a real-life example of nested loops.
Reason (R): The hour hand moves through 12 positions, while the minute hand moves through 60 positions within each hour.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (A) is false and (R) is true.
Which of the following converts "25" to 25.0?
- Double.Parsedouble("25")
- Double.parse("25")
- Double.parseDouble("25")
- Double.parseDouble(25)
Consider the program segment:
int p = 0; for(p = 4; p > 0; p -= 2); System.out.print(p); System.out.println(p);The above statement will display:
- 42
- 4200
- 0
0 - 00