COMPSCI 121 Lecture Notes - Lecture 9: Square Root, Mutator Method, Global Sources

60 views2 pages

Document Summary

Declare attributes, will have default values of null, 0. 0, 0, false. Create constructor using parameters to assign to attributes. Methods public (return type: int, double, string, void) nameofmethod (datatype parameter) Make sure your return type matches what you are returning. Can use your created class to create method, you use your class as the return type public car maketwin(){ Car twin = new car(make, fuelcapacity, fuelamount); return twin; Method definition given in a class; that class is compiled. Methods can produce output, change object state, write stuff on the screen. Method data comes from parameters, object attributes, global sources public double getfuel(){return fuelamount;} Has a return statement public void setfuel(){fuelamount = amt;} One parameter all info comes from parameter but effect is to alter calling object. Information: flow from parameters, calling object attributes, possible global sources, to calling object or calling method or some variable on screen. Can have more than one constructor but have to have different parameters.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents