• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in ExamLab

 
Fissehaye Kahsay
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

shouldn't the output of the above code be "DemoC++". We are using super.s, so the upper class XClass has no knowledge about the subclass YClass. Any help please and takes for your time
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess you are using the super keyword wrong...super is used when a variable in the current class shadows the variable in the superclass.....try this example...then may you will understand....am not sure if am right....what i have done here is created a new string s in the YClass.....
 
Dejan Miler
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys.


Here we just accessing to superclass variable and give it new value and that happens before this line of code

And that is all.

Dejan.
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dejan is absolutely right.....bang on target...we have changed the value of superclass's variable and using super.s we are trying to find out the value of s..which is c#....
 
Ajit Sawant
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Concept that is being show is that at the time of object creation initializwer are executed and that the super class intializer in run before the subclass. Actually the intializer is run before it own constructor is run.

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