lecture20-Objects3

lecture20-Objects3 - Lecture 20: Objects: Scope,...

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

View Full Document Right Arrow Icon
Lecture 20: Objects: Scope, capsulation Inheritance Encapsulation, Inheritance CS 170, Section 000 5 November 2009 11/10/2009 CS170, Section 000, Fall 2009 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture Plan ± Review (sort of): Arrays of Objects ± Logistics ± HW6 questions (due tomorrow) ¾ Basic Objects (wrap-up): Ch 9 ¾ Mutability, Scope, this keyword, Encapsulation ¾ if time: StackOfIntegers example (9.8) ¾ Inheritance: Ch 10.1-5 xtending asses per yword method verriding ¾ Extending classes, super keyword, method overriding CS170, Section 000, Fall 2009 2
Background image of page 2
Logistics Homework 6: Due Wed Nov 11 th Poker simulation Midterm 2: Tuesday, Nov 17 th ¾ Review Session: Monday Nov 16, 4:15-6pm, W301 11/10/2009 CS170, Section 000, Fall 2009 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Array of Objects Circle[] circleArray = new Circle[10]; An array of objects is actually an array of reference variables Invoking circleArray[1].getArea() involves two levels f referencing of referencing circleArray references to the entire array circleArray[1] references to a Circle object. 4
Background image of page 4
Array of Objects, cont. Circle[] circleArray = new Circle[10]; 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
Array of Objects, cont. Compute total area covered by all the circles TotalArea.java 6
Background image of page 6
Practice problems Basic concept of objects and classes 7.5 Static variables and methods .10, 7.12 7.10, 7.12 Visibility modifiers, accessor and mutator methods 15 7.15 Using Objects in Arrays and methods 7.17, 7.20
Background image of page 7

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

View Full DocumentRight Arrow Icon
Lecture Plan ¾ Basic Objects (wrap-up): Ch 9 ¾ Mutability, Scope, this keyword, Encapsulation ¾ if time: StackOfIntegers example (9.8) ¾ Inheritance: Ch 10.1-5 xtending classes super keyword method overriding ¾ Extending classes, super keyword, method overriding CS170, Section 000, Fall 2009 8
Background image of page 8
Visibility Modifiers and Accessor/Mutator Methods By default, the class, variable, or method can be accessed by any class in the same package. ) public The class, data, or method is visible to any class in any package. ) private he data or methods can be accessed only by the The data or methods can be accessed only by the declaring class. 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
Example of Data Field Encapsulation Circle ii d i t -radius: double -numberOfObjects: int Circle() The radius of this circle (default: 1.0). The number of circle objects created. onstructs a default circle object The - sign indicates private modifier +Circle() +Circle(radius: double) +getRadius(): double +setRadius(radius: double): void Constructs a default circle object. Constructs a circle object with the specified radius. Returns the radius of this circle. Sets a new radius for this circle. +getNumberOfObject(): int +getArea(): double Returns the number of circle objects created. Returns the area of this circle. Circle3 .java estCircle3 va 10 j TestCircle3 .java
Background image of page 10
Immutable Classes class Student{ rivate ringBuffer rivateName private StringBuffer privateName; Student(String n){ privateName = new StringBuffer(n); } public StringBuffer getName(return privateName); //no “setName” method!
Background image of page 11

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

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

Page1 / 54

lecture20-Objects3 - Lecture 20: Objects: Scope,...

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

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