Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to invoke the first superclass constructer with out invoking the subclass constructer..?

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All

The program discription :_




Kindly tell me the statement to invoke A default constructer from c default constructer with out using executing B default constructer
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. this() and super() can only be called from a constructor context. And you can't do super().super() or something like that. Only the super class is visible. If you just want an A object then just directly call the constructor.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not Possible. You cant break the Constructor Chaining.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouter win the race!
 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot....
 
salvin francis
Bartender
Posts: 1280
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me "try" to explain why ....
ahem

C extends B and B extends A

So, if you want to create an Object of C, A has to be created *, or a better word would be .. Constructed.
Next, B will be constructed and then C.

Thus the constructors will be called in that order.
You can choose to call a specific Immediate parent constructor by using super keyword

However skipping B's constructor would mean that C will be created without B and thus will not work.

* Note that only one object is created not 3
 
Campbell Ritchie
Sheriff
Pie
Posts: 49424
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better to say that part of the C object which is unchanged from A is created, then that part unchanged from B, but not in A, then the parts only in C.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic