programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
Hello. It's the first time for me to post a message.
----------------------------
public class MethodOver{
private int x,y;
private float z;
public void setVar(int a, int b, float c){
x = a;
y = b;
z = c;
}
}
Which two overload the setVar method?
A. void setVar (int a, int b, float c){x=a; y=b; z=c;}
B. public void setVar (int a, float c, int b) {setVar(a,b,c);}
C. public void setVar (int a, float c, int b){this(a,b,c);}
D. public void setVar (int a, float b){x=a;z=b;}
E. public void setVar (int ax, int by, float cz){x=ax; y=by; z=cz;}
-----------------------------
I think that the answer should be B, C, D while the suggested answer are B and D only.
I would like to ask that why C is incorrected?

Ranch Hand
Posts: 1090
• Number of slices to send:
Optional 'thank-you' note:
Hi WK
Well option C is correct but its implementation is wrong I guess that's why they have not included C in the correct answer set. {this(a,b,c);} this is wrong. But this no doubte a badly worded question.
[ June 09, 2003: Message edited by: Anupam Sinha ]

Ranch Hand
Posts: 67
• Number of slices to send:
Optional 'thank-you' note:

The above code will give compile time error.
Using the keyword *this* like in the above example is wrong. It can only be in the first line of a constructor. this(a, b, c) will try to call a constructor with 3 args of compatible data type.

Anupam Sinha
Ranch Hand
Posts: 1090
• Number of slices to send:
Optional 'thank-you' note:
Hi Rajeshwari
As I said earlier that though the implementation of the method is wrong I guess you can still call it an overloaded method. I would call it an incorrectly implemented overloaded method.

WK Lee
Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
Anupam & Rajeshwari, thanks for your helping...
I get it now.

Ranch Hand
Posts: 867
• Number of slices to send:
Optional 'thank-you' note:
Let me edit the question
A. void setVar (int a, int b, float c)
B. public void setVar (int a, float c, int b)
C. public void setVar (int a, float c, int b)
D. public void setVar (int a, float b)
E. public void setVar (int ax, int by, float cz)

[ June 10, 2003: Message edited by: siu chung man ]