Home > Net >  How do I access the variables of the method argument?
How do I access the variables of the method argument?

Time:10-06

Methods

There are instance variables for the numerator and denominator but I don't know if using "this" would get the argument's variables or the variables for the Fraction that the method is used on. How would I get both of their variables? There's no get method btw.

CodePudding user response:

"this" keyword is used for the object that contains the method, so you would use this.variable if you are referring to something outside of the method, and would not use it when referring to the parameters passed to the method. A better explanation of the "this" keyword in Java can be found here: https://www.w3schools.com/java/ref_keyword_this.asp

CodePudding user response:

If your public variable and method argument have same name use this

public variable - this.yourVariable

method argument -yourVariable

  • Related