• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor

 
swapnil paranjape
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain the output

i was expecting the output as
a=10
b=16

but output is
b = 0
b = 16

actualy subclass constructor should call super (base class constructor) but thats is not happening here..please explain

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is what you were trying to do...



The function call is over ridden, so the super constructor calls the derived class call() function. At this point of time b is not initialized with 16 so it prints 0. I changed the function name from call to call_one in the base class.
 
Flom Xanther
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just for your info,
if you would make call() in bc private, then the result is what you expect..

Because private methods/attributes are not inherited, so no way for polymorphism..

regards,
Flom
 
swapnil paranjape
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when the base class contructor calls the method call() its actually this.call() (am i right?) so it should invoke the base class call method. why the call method from subclass is called?

please explain.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic