7-20101019 - Introduction to OO Program Design Software...

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

View Full Document Right Arrow Icon
Introduction to OO Program Design Software College of SCU Instructor: Shu Li Email: [email protected]
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Unit 2.1 Implementing Classes 2.1.1 Defining Classes 2.1.2 Inheritance 2.1.3 Method equals and Method toString 2.1.5 Implementing the Library System
Background image of page 2
3 Define Classes class classname extends superclass{ type instance-variable1; type instance-variable2; // … type instance-variableN; type methodname1(parameter-list){ // body of method } // … type methodnameN(parameter-list){ // body of method } } attribute class name method
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Point Class class Point { private int x, y; public Point() { x=0; y=0; t } public Point(int x, int y) { this.x=x; this.y=y; } public void move(int newX, int newY) { x = newX; y = newY; } t }
Background image of page 4
5 Create Object Declare o Point p;// +< / Instantiation o o new e 0 6 e 0 6 Create o Y f W D<
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Creating objects of a class Point p   new Point(20,23); = 0x0000 20 23 0xFF00
Background image of page 6
7 Creating objects of a class P pointOne Q pointTwo Before Assignment After Assignment Q pointTwo P pointOne Point pointOne = new Point(); Point pointTwo = new Point() ; pointOne = pointTwo;
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Automatic garbage collection The object does not have a reference and cannot be used in future. The object becomes a candidate for automatic garbage collection. Java automatically collects garbage periodically and releases the memory used to be used in the future. P
Background image of page 8
9 Accessing Object/Point Data Similar to C syntax for accessing data defined in a structure. Using object variable objectReference.variable p.x= 10; Using object method objectReference.methodName([paramlist]); p.move(30,20);
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Class Diagram to JAVA Code Point -x : int -y : int +Point() +Point(newX : int, newY : int) +getX() : int +getY() : int +setX(newX : int) +setY(newY : int) public class Point { private int x; private int y; }
Background image of page 10
11 Class Diagram to JAVA Code Point -x : int -y : int +Point() +Point(newX : int, newY : int) +getX() : int +getY() : int +setX(newX : int) +setY(newY : int) public class Point { public Point(int newX, int newY) { x = newX; y = newY; } public Point(){ x = 0; y = 0; } }
Background image of page 11

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

View Full DocumentRight Arrow Icon
12 Class Diagram to JAVA Code Point -x : int -y : int +Point() +Point(newX : int, newY : int) +getX() : int +getY() : int +setX(newX : int) +setY(newY : int) public class Point { public int getX() { return x; } public int getY() { return y; } }
Background image of page 12
13 Class Diagram to JAVA Code Point -x : int -y : int +Point() +Point(newX : int, newY : int) +getX() : int +getY() : int +setX(newX : int) +setY(newY : int) public class Point { public void setX(int newX) { x = newX; } public void setY(int newY) { y = newY; } }
Background image of page 13

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

View Full DocumentRight Arrow Icon
14 Class Diagram to JAVA Code public class Point { public static void main(String[] args) { Point pointOne = new Point(10, 100); System.out.println("x: " + pointOne.getX()); System.out.println("y: " + pointOne.getY()); pointOne.setX(20); pointOne.setY(200); System.out.println("new x: " + pointOne.getX()); System.out.println("new y: " + pointOne.getY()); } sent ‘message’ to pointOne
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/12/2011 for the course ECON 101 taught by Professor Professor during the Spring '10 term at Cisco Junior College.

Page1 / 93

7-20101019 - Introduction to OO Program Design Software...

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

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