lecture25

lecture25 - CS111: Intro to Computer Science Lecture 25...

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

View Full Document Right Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 25 CS111: Intro to Computer CS111: Intro to Computer Science Science Lecture 25 Programs with multiple classes Inheritance
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 25 The Object Metaphor The Object Metaphor The world is made up of objects which interact with each other E.g. a count-down timer A real world object is a member of some class e.g. the class of count-down timers The class of an object determines What constitutes its state e.g. a timer has a number of ticks left before rining How it interacts with other objects
Background image of page 2
CS111: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 25 Objects and Messages Objects and Messages Objects interact with other objects by sending “messages” A message is in fact a fancy way of calling a method Java syntax for sending a message: name . substring (1, 4) Object to method arguments receive name message
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 25 The receiving object The receiving object What method actually gets called depends on The method name The class of the receiving object Java looks for a method with the given name in the class of the receiving object Many different classes can have method with the same name: See getCount in CountDown.java and County.java Which method gets called depends on the class of the receiving object
Background image of page 4
CS111: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 25 The receiving object and this The receiving object and this Every non-static method has a variable named this It does not need to be declared Its value is the receiving object of the message that invoked the current method It is read-only The variable this can be used to refer to the data fields of the receiving object E.g. this. count in CountDown.java
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 25 The receiving object and static The receiving object and static methods methods A static method is not called by sending a message, it is just called, so A static method has no receiving object The thing before the period is a class name, not an object expression E.g. Math.sqrt(x) The variable this is not defined in static methods
Background image of page 6
CS111: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 25 Interface Interface vs vs implementation implementation Interface: what you need to know to use a class Method names What each method accomplishes Implementation: details of the class’s code How each method accomplishes what it does
Background image of page 7

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

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 8 Lecture 25 Encapsulation Encapsulation Goal: break program into parts Classes or small groups of classes Code in one part can depend on the interface of another part But cannot depend on the implementation of another part Therefore, you can change the implementation of any part As long as the interface is unchanged Without worrying about breaking any other part
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/01/2011 for the course 198 111 at Rutgers.

Page1 / 44

lecture25 - CS111: Intro to Computer Science Lecture 25...

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

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