• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

this vs super question

 
Sergej Smoljanov
Ranch Hand
Posts: 468
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what difference in variable this and super.
why Test t = this; and Base b = super ; - not ok?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
super can't be used as a reference in the same way this can. It's used in two specific circumstances:

- To call the base class version of a method
- To call a base class constructor

Remember that this refers to a Test object in this case, which is also a Base object. So you can assign this to a Base reference variable. If super was allowed there, what would you expect it to do that is any different?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic