
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Where and How is Import Statement Used in Java Programs
Wan import statement in Java is used to −
Import user defined classes/Interfaces
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
In case of 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 &minsu;
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
Advertisements