- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are static imports in java? Example.
Whenever you need to access a class which is not in the current package of the program you need to import that particular class using the import statement.
Example
In the following example, we are using the Math class to find the square root of a number, therefore, first of all, w should import this class using the import statement.
import java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(Math.sqrt(169)); } }
Output
13.0
Static imports
static import allows to access the static members of a class without class qualifications. For Example, to access the static methods you need to call the using class name:
Math.sqrt(169);
But, using static import you can access the static methods directly.
Example
import static java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(sqrt(169)); } }
Output
13.0
- Related Articles
- Static blocks in Java with example
- What are Class/Static methods in Java?
- Are values returned by static method are static in java?
- What is Static Friction? Give an example.
- Package Imports in JShell of Java 9
- What are static members of a Java class?
- Are static methods inherited in Java?
- What are differences between static binding and dynamic binding in Java?
- Are static local variables allowed in Java?
- What is static binding in Java?
- What is static import in Java?
- What is blank final variable? What are Static blank final variables in Java?
- What are the restrictions imposed on a static method or a static block of code in java?
- What are the steps to read static members in a Java class?
- What are the differences between import and static import statements in Java?

Advertisements