Java static Import

Introduction

Java static import expands the import keyword.

static import can import the static members from a type.

There are two general forms of the import static statement.

import static pkg.type-name.static-member-name  ; 
import static pkg.type-name .*; 

// Use static import to bring sqrt() and pow() into view. 
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

public class Main {
  public static void main(String args[]) {
    double side1, side2;
    double hypot;

    side1 = 3.0;// w w w  . ja v  a  2 s. c  o m
    side2 = 4.0;

    hypot = sqrt(pow(side1, 2) + pow(side2, 2));

    System.out.println(hypot);
  }
}



PreviousNext

Related