06Objects - CSE 114 Computer Science I Objects Lake...

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

View Full Document Right Arrow Icon
CSE 114 Computer Science I Objects Lake Superior, Michigan
Background image of page 1

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

View Full DocumentRight Arrow Icon
Primitives vs. Objects So far we have seen mostly primitives they store single values Ex: int i = 6; Now we will define/use our own complex types Classes/Objects they can store multiple values Ex: Die die; What objects have we used already?
Background image of page 2
Object vs. Class What’s the difference? Class: defines a type, it’s a blueprint for making objects Object a variable of type Class Ex: String s = "Hello"; What’s the class name? What’s the object name? All String objects have the same instance variables (but different values) and methods.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Die Object STATE (What information describes it?) Number of Faces – maximum numbers on dice Value facing up – number on upward face BEHAVIOR (What can we do with it?) Initialize – initializes state Roll – choose a random up-face value Read the value – get current up-face value
Background image of page 4
The Basics of Defining Classes General format of a class: public class ClassName { instance variable declaration(s) method definition(s) } Instance variables == state Methods == behavior
Background image of page 5

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

View Full DocumentRight Arrow Icon
'.' When you make an object, you have access to: its instance variables its methods, which may use its instance variables '.' – used to access public instance variables and methods for a given object variable soon we’ll see we have options other than public Example: String name = "Richard"; String nickname = name.substring(0, 4);
Background image of page 6
But what does '.' really do?
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.

This note was uploaded on 04/13/2010 for the course CSE 114 taught by Professor Tashbook during the Spring '08 term at SUNY Stony Brook.

Page1 / 19

06Objects - CSE 114 Computer Science I Objects Lake...

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