Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Constructor magic?

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All:
Snippet of code taken from one of the questions contained in the K&B SCJP6 Study Guide Master Exam:


I understand, according to the same book I referred to, that if I coded a constructor in my class then the compiler will not provide a no-arg constructor for me. OK, quick question: Can someone please tell me why the line of code at "Line 1" does not cause a compiler error?
Thank you for your time
Gary
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
varargs allows you to pass zero to any number of arguments. Hence the parameter variable is treated as an empty array when you send nothing to it.

Have a print statement and see the length of nums
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear John,

It's a valuable information. Excellent.
BR,
 
Gary Marshall
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Got it. I understand. Thank you for your time.
Gary
 
this llama doesn't want your drama, he just wants this tiny ad for his mama
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic