CS 100, Summer 2001 Tuesday, 7/31 Lecture 19 ----------------------------------------------------------------------- Announcements: + Exercise 14 due 8/1 + Pick up graded Exercise 12, Project 1 + reading: Savitch 7.2, 7.3 ----------------------------------------------------------------------- Topics: + Exercise 13 + Project 2 + Pass by value + Public/protected/private modifiers ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Exercise 13 - Keep it with you so we can discuss it - I realize that this means you have a chance to scribble in the right answers, but recall that the point of these exercises is to give YOU a chance to see what you know and understand. So if you copy down the right answer but don't understand it, it'll be your loss, not ours.. If you copy down the right answer and you DO understand it, then great! ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Project 2 - Inheritance: getting stuff defined by another class "for free" - Interfaces: making a commitment to define something *declared* (but not implemented) by another class - Comparable Interface: requires that you defined a "compareTo" method - then you can write methods to take in Comparable arrays - compareTo must take in an Object, then cast it to the proper type (why?) ---------------------------------------------------------------------- ---------------------------------------------------------------------- + note on shadowing: I lied. You can get at the "global" i. How? - Problem1.i (it's a static, i.e. class, variable) + Pass by value - Java passes items by value - but for objects, it's the reference that's being passed (or returned) - so you can actually change objects after passing them into a method (this is often thought of as pass by reference, but don't confuse yourself) - EXAMPLES: - Pass1.java: you can modify objects passed as method arguments, because the reference is what's passed - likewise, you can modify objects returned from a method, because the reference is what's returned - Pass2.java: assigning a reference to a new place doesn't change whatever it used to point to - Pass3.java: aliasing allows you to change whatever the alias (reference) currently points to - remember, variable names only apply within their SCOPE. So I could change the formal parameters in change() to be d1 and d2, instead of x and y, and the "real" d2 (in main()) would still be unchanged. ---------------------------------------------------------------------- ---------------------------------------------------------------------- + Public/protected/private modifiers - public: accessible anywhere - protected: accessible in the class and in inheriting classes and by the package - default: accessible in the "package" (project) - private: only accessible inside the class (not by inheriting classes) ---------------------------------------------------------------------- ---------------------------------------------------------------------- PICK UP graded Exercise 12 and Project 1, handed out Exercise 14 HAND IN your Exercise 13