Lecture8

Lecture8 - Static methods can only refer to static data and...

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

View Full Document Right Arrow Icon
1 Static methods can only refer to static data and the data passed in the argument list. public class Test { public final static double PI = 3.14; // static or "class" variable double b = 3; // non-static or "instance" variable public double func (double x) { return (4.0 * Math.sin (x)**2); } public static double tfunc (double x) { return (3.0 * x * PI); } public static double wfunc (double x) { return (3.0 * x * b); // Error! Cannot use nonstatic variable b in a class method. }}
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 Chapter 6 Using the Java Library Class libraries - A class that is already defined and can be used in your program. Similar classes are normally grouped together as a library. Packages The classes of the Java standard class library are organized into packages java.lang Provides classes that are fundamental to the design of the Java programming language, for instance, class math, class string, class system. java.util the collections framework, legacy collection classes, date and time facilities or a random-number generator, for instance, random class and scanner class.
Background image of page 2
3 The import Declaration When you want to use a class from a package, you can import the class, and then use just the class name import java.util.Scanner; To import all classes in a particular package, you can use the * wildcard character import java.util.*;
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 The java.lang Package All classes of the java.lang package are imported automatically into all programs It's as if all programs contain the following line: import java.lang.*; That's why we didn't have to import the System or String classes explicitly in earlier programs The Scanner class, on the other hand, is part of the java.util package, and therefore must be imported.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/12/2010 for the course COE 318 taught by Professor Ken during the Spring '08 term at Ryerson.

Page1 / 14

Lecture8 - Static methods can only refer to static data and...

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

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