• Post Reply Bookmark Topic Watch Topic
  • New Topic

overriding constructors?  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i override constructors? If not, why?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kri shan wrote:Can i override constructors? If not, why?


No, you can't. Why not: it wouldn't make much sense. How can you override when you haven't created the object yet?
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can you override when you haven't created the object yet?
How object is created during overloaded constructors?
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kri shan wrote:
How object is created during overloaded constructors?


overloading and overriding are two completely different things. Overriding is how Java implements polypmorphism or virtual functions, and requires a formed object for it to occur. Overloading on the other hand simply means that two or more methods or two or more constructors have the same name, does not require OOPS (and in fact is a feature of many non-OOPs procedural languages) and does not require an object for it to work.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's helpful to think of constructors as class methods that
are available just after the class is loaded. Is this an okay model?
After all, they must exist before the objects they create.
Jim ...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!