COMP 202 Lecture Notes - Lecture 25: Local Variable
![COMP 202 Full Course Notes](https://new-docs-thumbs.oneclass.com/doc_thumbnails/list_view/2177048-class-notes-ca-mcgill-comp-202-lecture10.jpg)
100
COMP 202 Full Course Notes
Verified Note
100 documents
Document Summary
Example: write a class to describe a vector. A print method that displays all of the coordinates. A static add method that takes as input two vector objects and returns a new vector containing the sum. (z=x+y) static. See mycourses for example code vector and testvector . If you want to do v. print() (ie: call it on a particular vector object), you will need a non-static method (public void print(){ ) Public class testvector contains the main method where we use the vector class. When you initialize vector v = new vector[]; you get a nullpointerexception with you do v. print() This is because the array coords hasn"t been assigned a value in the main method. This happens when we write two methods in the same class, with the same name, but different input. You cannot overload a method by just changing the return type/static. You have to change the input in a meaningful way number of inputs, type of input.