{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 06-Methods

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

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

View Full Document Right Arrow Icon
1 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 Congratulations!! 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. Take advantage: see videos of the 11:15 lecture for CS1110 on www.VideoNote.com. Log in with your Cornell netid The last slide concerns local variables –variables declared within a method body. We don’t have time to discuss them. You are responsible for knowing about local variables. Read pp. 76-78 (sec. 2.3.7). 2 /** An instance keeps information about a book chapter */ public class Chapter { // class invariant: meanings of fields and constraints on them private int number; // 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) } 3 /** Constructor: a chapter with title t, number n, and previous chapter null.*/ public Chapter(String t, int n) { title= t; number= n; previous= null; } Within the body (between { }) is the sequence of statements to execute when the method is called.
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}