Lecture 06-Methods - CS1110 Thursday 16 February 2010 Congratulations You now know the basics of OO(object-orientation Discussion of Methods

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 ±elds 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 DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/27/2010 for the course CS 9339 at Cornell University (Engineering School).

Page1 / 2

Lecture 06-Methods - CS1110 Thursday 16 February 2010 Congratulations You now know the basics of OO(object-orientation Discussion of Methods

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

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