{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

A static field publicclasshelloagainworld

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Math { … public sta0c double random() { … } } •  Static methods are called directly on the class, without creating an object double x = Math.random(); CPSC 324 ‐‐ Spring 2010 Static Methods •  Each method must provide 19 This one is a bit tricky We’ll talk about it later –  Access level/visibility … public, protected, private, or none –  Whether it is staLc or non-static (default) –  Return type (primitive, array, or object type) –  Method name –  Zero or more arguments (type and name) –  Method body (in {}’s) •  Static methods can only work at the “class” level •  They can only access local variables (including arguments), static fields, and static methods CPSC 324 ‐‐ Spring 2010 20 10 1/19/10 Static Methods •  Is this OK? a static field public class HelloAgainWorld { public staLc String theString = “Hello World!”; public staLc String getString() { return theString; } static method t...
View Full Document

{[ snackBarMessage ]}