• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This and super keyword query

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wish to know in how many ways can these two keywords be used :
this and super keyword
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really sure what you want to ask here, but this and super can be used to call constructors, methods and fields of current class and super class respectively...
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java key word 'this' always refers to the current object, like; this.doSomething() for
a method, or this.myRefVar for a member variable. The presence of 'this' is often
inferred by the compiler, as doSomething() and this.doSomething() mean the same
thing. Also, 'this' is often used within a constructor to invoke a different constructor,
as in; this(parm1, parm2, etc). The specific constructor invoked is based on matching
up the constructor and call parameter types. Key word 'super' is used in the same ways,
but refers to constructors, methods and member variables not in the current object, but
rather, above it in the inheritance tree. Does this help?

Jim ... ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic