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.

 
 

Share on Google+Share on Google+

SCJP Module-4 Question-1

Ads

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.

Advertisements

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