SCJP Module-4 Question-1


 

SCJP Module-4 Question-1

The program given below checks you understanding of methods and their declaration. It is also very useful for SCJP examination.

The program given below checks you understanding of methods and their declaration. It is also very useful for SCJP examination.

Which code line/lines should be placed at line 6 to run following program ?

1. class Example1{
2. public static void main(String[] args) {
3. Twin(1);
4. Twin(1,2);
5. }
6. // place the code here
7. }

Which statements below can be placed at line 6 to run above program ?

1.    static void Twin(int i ) { }

2.    static void Twin(a,b,c) {  }  

3.     static void Twin(int i, int j) { }

4.    need not to add any code to run this program.

Answer :

(1) & (3)

Explanation :

In Method overloading, same name methods with different number of arguments can be used. Methods must be define before using it.

Ads