COMP 202 Lecture Notes - Lecture 26: Local Variable, Global Variable

19 views2 pages
jc123 and 40170 others unlocked
COMP 202 Full Course Notes
100
COMP 202 Full Course Notes
Verified Note
100 documents

Document Summary

The this keyword is use to refer to the object on which a non-static method was called. Instead of passing v as input, we can use the this keyword inside the print method to refer to it. No! this refers to the object instance that calls the method. A static method is called from the name of the class, and not from a particular object. The static method wold have nothing to refer to. In a static method, you would use the name of the class instead of the word this if you wanted to specify the global vs local variable. Add a method getmagnitude to the vector class. Recall that the magnitude of a vector v with dimension d. We"ll make this static, so you don"t need to pass a vector as input, you can call it on a particular vector.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents