set10 - Programming in Java 1 Java Classes Similar to C...

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

View Full Document Right Arrow Icon
1 Programming in Java Programming in Java
Background image of page 1

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

View Full DocumentRight Arrow Icon
Last modified: Jan. 2001 2 Java Classes Java Classes Similar to C++ with minor differences:The Example: class Dog { . . . } Data member and functions
Background image of page 2
Last modified: Jan. 2001 3 Data Members and Methods Data Members and Methods Data members ( fields) and member functions ( methods) are defined inside the class declaration. Instance variables and methods are associated with each instance of the class. Methods (functions) definitions are similar to C++.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Last modified: Jan. 2001 4 public class Point { private double x, y; public void setx(double value) { x = value; } public void sety(double value) { y = value; } } Data Members and Methods Data Members and Methods (continued) (continued) Example: instance variables instance methods
Background image of page 4
Last modified: Jan. 2001 5 . . Point myPoint = new Point(); myPoint.setx(3.5); myPoint.sety(-7.0); Point anotherPoint = new Point(); anotherPoint.setx(125.0); anotherPoint.sety(15.0); . . Data Members and Methods Data Members and Methods (continued) (continued)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Last modified: Jan. 2001 6 Fields and Methods (continued) Fields and Methods (continued) null myPoint : x = 0.0 y = 0.0 * 3.5 y = -7.0 null anotherPoint : x = 0.0 y = 0.0 * x = 125.0 y = 15.0
Background image of page 6
7 Public class Point { private double x, y; private static int classID = 0; public void setx(double value) { x = value; } public void sety(double value) { y = value; } public static int classID() { return classID;
Background image of page 7

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

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

This note was uploaded on 07/10/2011 for the course ENEL 409 taught by Professor Moussavi during the Fall '11 term at University of Calgary.

Page1 / 21

set10 - Programming in Java 1 Java Classes Similar to C...

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

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