lec13Feb12008

lec13Feb12008 - --> get , set methods Direct access from...

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

View Full Document Right Arrow Icon
Lecture 13 February 1, 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
Recap Class Object State Behavior QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this picture. Car.java QuickTime™ and a TIFF (Uncompressed) decompressor are needed to see this picture. Name: Astron Martin Type: DBS Price: $265000 Owner: Ladan Power: 530 hp Well defined operations associated with a car. e.g. changing the price, owner, etc
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Scope of variables Depends on where a variable is declared Instance variables (member variables) – price (in the Car class), x and y (in the Point class) Local variables – for(int j = 0; j < 10; j++) System.out.println(j); Parameters public int exponentiate(int base, int exponent) { }
Background image of page 8
Visibility Modifiers Control access Reserved words: public , private , …. Instance variables should be declared private (Encapsulation) Need a way to access and modify data value
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

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

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

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

View Full DocumentRight Arrow Icon
Background image of page 16
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: --> get , set methods Direct access from outside the object May be used anywhere inside the class definition but not externally import java.util.Scanner; public class Point { private int x; private int y; public Point() { x = 0; y = 0; } public Point(int firstVal, int secondVal) { x = firstVal; y = secondVal; } public int getX() { return x; } public void setX(int newX) { x = newX; } // Do the same for y public void printXY() { System.out.println("(" + x + " , " + y + ")"); } public static void main(String args) { Point firstPoint = new Point(); Scanner scan = new Scanner(System.in); int valX, valY; System.out.println("Enter X"); valX = scan.nextInt(); System.out.println("Enter Y"); valY = scan.nextInt(); Point secondPoint = new Point(valX, valY); secondPoint.printXY(); } }...
View Full Document

This note was uploaded on 04/14/2008 for the course COMP 202 taught by Professor Verbrugge during the Winter '07 term at McGill.

Page1 / 16

lec13Feb12008 - --> get , set methods Direct access from...

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

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