This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please Explain this Constructor parameter type ?

 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


what is the meaning of this 3 dots ? This is a code which is related to my assignment .I'm trying to understand this !
Can we have this kind of parameters in the method also ?

what i noticed here was when I can call this constructor
DelaunayPoint d1=new DelaunayPoint (3,4,5);

or

DelaunayPoint d1=new DelaunayPoint (3,4);

So this 3 dots means you can send any number of arguments below 3 ? Is that so ?Confused ! Please Help Thanks !




 
Vijitha Kumara
Bartender
Posts: 3953
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lakmal padmakumara wrote:

what is the meaning of this 3 dots ?

That denotes var-args, you can send any number of arguments to that method/constructor which matches the type of the argument defined.
 
Rok Štelcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Check following link for understanding:
http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html


Regards,
Rok
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... represents var-args operator. You can pass as many multiple values of the same type as you want or array of the same type. Kindly refer the below example for better understanding




The out put of the above code would be -1 2 3 4 35
I hope, this would clear all your doubts.
 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Thanks !!! You People are really helpful !! It helped me a lot !!!
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!