• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructors with var-args?  RSS feed

 
Neha Bhattad
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...
 
Prahlad Joshi
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
 
Burkhard Hassel
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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!