COE 318 Lecture Notes - Lecture 2: Instance Variable
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)"