Lecture 06-Methods - CS1110 Thursday, 16 February 2010...

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

View Full Document Right Arrow Icon
1 CS1110 Thursday, 16 February 2010 Discussion of Methods: Executing method calls. If-statements. The return statement in a function. Local variables. For this and next lecture: Read chapter 2, but NOT 2.3.8!!!! Do the self-review exercises in 2.3.4 Congrats!! You now know the basics of OO (object-orientation). Sit next to someone. Today, we do some work in pairs. Get out a blank sheet of paper. Get out Iclicker. The last slide: local variables –variables declared within a method body. No time to discuss them. You are responsible for local variables. Read pp. 76-78 (sec. 2.3.7).
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 CS1110 Thursday, 16 February 2010 A2 will take you 10-15 minutes. Due on Thursday , in class. Do it this weekend, not two minutes before class on Thursday Sit next to someone. Today, we do some work in pairs. Get out a blank sheet of paper. Get out Iclicker.
Background image of page 2
3 /** An instance keeps info about a book chapter */ public class Chapter { // class invariant: meanings of fields and constraints on them private int numb; // the chapter number, in range 0. .100 private String title; // chapter title private Chapter prev; // instance for the previous chapter // (null if no previous chapter) } a0 Chapter numb 2 title “objects” prev a5 a5 Chapter numb 1 title “intro” prev null c a0
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 /** An instance keeps info about a book chapter */ public class Chapter { // class invariant: meanings of fields and constraints on them private int numb; // the chapter number, in range 0. .100 private String title; // chapter title private Chapter prev; // instance for the previous chapter // (null if no previous chapter) } /** Change the previous chapter title to t. Precondition: previous chapter not null. */ public void changePrevTitle (String t) { prev.title= t; } A. It will work B. It won’t compile --it has a syntax error C. It will compile --but it won’t run right
Background image of page 4
5 /** Constructor: a chapter with title t,
Background image of page 5

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

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

Page1 / 16

Lecture 06-Methods - CS1110 Thursday, 16 February 2010...

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

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