COMPSCI 121 Lecture 8: Feb 21

33 views2 pages

Document Summary

A method definition is given in a class. In a second class an object is created, things happen, then the method above is invoked on the object. Exam material will be up to week 5. String, how to call methods, write methods, if statements, data types, classes, objects model. Can"t have two variables in the same scope with the same name but they can be in different scopes. Know how to make a constructor and write a method for exam. Constructor: public car(string what, double cap, double amt){ make = what; fuelcapacity = cap; fuelamount = amt; } Remember: you are writing code for other humans, make it readable and easy to understand. Return method: public double fillupcost(double galloncost){ return((fuelcapacity - fuelamount) * galloncost); } void means you don"t expect anything back, would use for a setter method, like setfuel() Getter method retrieves a value out of an object, like getmake()

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