lec03 - Lecture 3 Strings Objects & classes Board class...

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

View Full Document Right Arrow Icon
CS 125 Course Notes Lecture 3, Slide 1 Lecture 3 • Strings • Board class • Methods (Savitch 2.2)
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 125 Course Notes Lecture 3, Slide 2 What is an object? Informal definition: • An object is an entity that stores information about itself (in attributes) and has methods to modify or display the stored information.
Background image of page 2
CS 125 Course Notes Lecture 3, Slide 3 String • An object which holds a sequence of characters • String variables must be declared and initialized just like primitive types. Example: String myString; myString = “This is it.”; String greeting = “Hello.”;
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS 125 Course Notes Lecture 3, Slide 4 Assigning values to String objects Example: String name; name = “Troy”; System.out.println(name); name = “Lori”; System.out.println(name);
Background image of page 4
CS 125 Course Notes Lecture 3, Slide 5 Concatenation • Joins two strings into one Example: String firstPart = “Hello”; String secondPart = “there.”; String combined = firstPart + secondPart; // value of combined is ________________ combined = firstPart + “ “ + secondPart; // value of combined is ________________ • For more info, see p. 77
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS 125 Course Notes Lecture 3, Slide 6 The + operator • Notice: int x = 10, y = 12, z; String s1 = “hi”, s2 = “bye”, s3; z = x + y; s3 = s1 + s2; • This is called overloading : the operator + does different things depending on the types of its operands.
Background image of page 6
Course Notes Lecture 3, Slide 7 Class • A type whose values are objects • Objects of the same type are said to belong to the same class . • Examples:
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 / 27

lec03 - Lecture 3 Strings Objects & classes Board class...

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