In JAVA there are three types
of import statements
1. Explicit
import – import java.util.ArrayList;
v It
will imports only ArrayList class into our class
v This
is highly recommended in real time
2. Implicit
import – import java.util.*;
v It
imports all the classes and interfaces presented in java.util package
v This
is not recommended in real time. It increases the burden on class loader as it
imports unnecessary things
3. Static import – import static
java.lang.Math.*;
v This was newly introduced in
jdk1.5
v This is for importing only static members
in a class
Example:
package pack2;
import static
java.lang.Math.*; // static import
public class FirstProg
{
public static int i=10;
static int j = 20;
public static void
main(String[] args) {
System.out.println(max(i,j));//max is
a static method. we are not using class name for calling because we static
imported
}
}
Important points:
Order
of statements in a class
Package statement
should
No comments:
Post a Comment