COMP 202 Lecture Notes - Lecture 25: Local Variable

27 views2 pages
jc123 and 40170 others unlocked
COMP 202 Full Course Notes
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.

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

Related Questions