Demonstrating static Import
Figure 8.14 demonstrates a static
import. Line 3 is a static
import declaration, which imports all static
fields and methods of class Math
from package java.lang
. Lines 9–12 access the Math
class’s static
fields E
(line 11) and PI
(line 12) and the static
methods sqrt
(line 9) and ceil
(line 10) without preceding the field names or method names with class name Math
and a dot.
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.