• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Constructors with var-args?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic