• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Q about Overload Method

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. It's the first time for me to post a message.
I've found a question about Overload Method:
----------------------------
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?
Thanks for your helping.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer C is not valid.

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anupam & Rajeshwari, thanks for your helping...
I get it now.
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me edit the question
Which method(s) are overloading method for the setVar?
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)
Welcome try to answer
Just want clear YOUR concept

[ June 10, 2003: Message edited by: siu chung man ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic