I am learning Java, and going through the document.
There is a line I am not able to understand -
... In addition, class methods can not use this keyword because of mentioning it There is no frequency for. ...
I thought it was only static class methods that could not use the
this keyword.
To test this, I writes the following, which compiles.
import java.math. *; Square point {public int x, y; Public point (int x, int y) {this.x = x; this. Y = y; } Public double getDistanceFromOrigin () {math.Sqrt back (this.x * this.x + this.y * this.y); }}
I have a class correct, in which a method refers to
this .
Am I doing things wrong in some way?
Stabilized methods of class are A "class method" is a method that is class oriented (using the
static keyword), in contrast to the object / example methods that you write, so that you can call those items You build on the basis of that class.
There are two object / instance methods in the code that you write, and there are no class methods. If you want a class method in Java, you make it static, and then you
This .
No comments:
Post a Comment