COE 318 Lecture Notes - Lecture 2: Instance Variable

53 views5 pages

Document Summary

Coe318 lecture notes week 2 (sept 12, 2011) Topics: what is an object, what is a class, examples, robot (a mutable class) Methods look like c functions and can take parameters and return some data type: for example, a person object might be asked for their name with the method getname(). Example: the robot class public class robot { //instance variables private int x; private int y; /** moves robot one space to the left */ A separate class contains a main method that tests the robot class: public class testrobot { public static void main(string[] args) { System. out. println("a"s x: " + a. getx()); for(int i = 0; i < 20; i++) { b. right(); b. up(); Example: the person class public class person { "m" : "f") + ")" uses the + operator to join (or concatenate) strings together: for example, "(" + "abc" + ")" yields the string: "(abc)"

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