This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Constructors with var-args?  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a constructor with var-args be used when a no-arg constructor is needed?

Will this work for all cases like when in deserialization the superclass(not implementing serialization) should have no-arg constructor?

Thanks...
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class a
{
a(int ...x)
{
System.out.printf("%s","in var arg consturctor");
}
}
class NewClass extends a{

/** Creates a new instance of NewClass */

NewClass()
{
super();


}
public static void main(String s[])
{
new NewClass();
}


}
//it works
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

Originally posted by Neha Bhattad:
Can a constructor with var-args be used when a no-arg constructor is needed?



can you show a situation where a no-arg constructor is needed?

Prahlad's example is just the other way round.


Bu.
[ August 26, 2007: Message edited by: Burkhard Hassel ]
 
Neha Bhattad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was mainly thinking about deserialization:
in deserialization the superclass(not implementing serialization) should have no-arg constructor else the readObject throws runtime exception.
What if the superclass has a no-arg constructor? Does it fit the bill?

The best way perhaps is to try it out...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!