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+
$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