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
- Spring '09
- Java Programming, Object-Oriented Programming, ‐‐ Spring
-
Click to edit the document details