lec19Feb1508

lec19Feb1508 - Lecture 19 Review Static Member fields We ve...

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

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

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

View Full Document Right Arrow Icon
Review … Static Member fields We’ ve seen two types of member variables : Instance variables: every object instance has its own set of these variables Static variables Also called class variables There’s only one copy of it for all instances Shared by all objects/instances of a class If an object changes the value of a static variable, all other objects see and access the new value
Background image of page 2
e.g. of a static member variable To keep track of the number of objects created: Have a (private) static variable Increase count whenever the constructor’s called private static int count = 0; . . . public square() { length = 2; count++; }
Background image of page 3

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

View Full Document Right Arrow Icon
A few points to remember … Memory space for a static variable is established when its class is referenced for the first time Constants are usually declared static
Background image of page 4
Static Methods Invoked through the class name A few examples: e.g. main method e.g. Math.sqrt(2); e.g. len = Math.sqrt(x*x + y*y)
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

lec19Feb1508 - Lecture 19 Review Static Member fields We ve...

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

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