L8 - CSE 114 Computer Science I Objects and Reference Bryce...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Bryce Canyon, Utah CSE 114 – Computer Science I Objects and Reference
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Classes Class —definition of a kind of object • Like an outline or plan for constructing specific objects • Class specifies what kind of data objects of that class have – Each object has the same data items but can have different values • Class specifies what methods each object will have – All objects of the same class have the same methods available to them
Background image of page 2
Class as an Outline Class Name: Automobile Data: amount of fuel ________ speed ________ license plate ________ Methods (actions): increaseSpeed: How: Press on gas pedal. stop: How: Press on brake pedal. Class Definition Objects that are instantiations of the class First Instantiation: Object name: patsCar amount of fuel: 10 gallons speed: 55 miles per hour license plate: “135 XJK” Second Instantiation: Object name: suesCar amount of fuel: 14 gallons speed: 0 miles per hour license plate: “SUES CAR” Third Instantiation: Object name: ronsCar amount of fuel: 2 gallons speed: 75 miles per hour license plate: “351 WLF”
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Objects • Variables that are named instances of a class – the class is their type • Have both data and methods – called members of the object • Data items are also called fields or instance variables Invoking a method means to call the method, i.e. execute the method. Ex: objectVariableName.method() objectVariableName is the calling (invoking) object
Background image of page 4
Containment • A class contains another class if it instantiates an object of that class – ―HAS-A‖ PairOfDice HAS-A Die
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PairOfDice dice Die die1 int upValue int numFaces Die die2 int upValue int numFaces RollGames main method Object Variables as Instance Variables for other Objects
Background image of page 6
Primitive Types vs. Objects (Class Types) • Primitive variables: – assigned a memory location when declared
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

L8 - CSE 114 Computer Science I Objects and Reference Bryce...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online