Local Variable ,Package & import


 

Local Variable ,Package & import

In this SCJP Section, you will learn about Local Variable ,Package & import of java

In this SCJP Section, you will learn about Local Variable ,Package & import of java

Local Variable ,Package & import

A local variable has a local scope.Such a variable is accessible only from the function or block in which it is declared.

Example of Local variable :

The class variable are declared in the class but not within methods of any class. Whereas the local variable exits within the methods of any class. Below two program are shown which help you to understand the difference between the class and local variable :

Showing Local Variable


public class LocalVar {
public static void main(String args[]) {
int localvariable = 101;
System.out.print(localvariable);
}
}

Showing the Class Variable

public class ClassVar {
private static int classVariable;

public static void main(String args[]) {
classVariable = 101;
System.out.print(classVariable);
}
}

Package & import

Java classes can be grouped together in packages. A package name is the same as the directory (folder) name which contains the .java files. You declare packages when you define your Java program, and you name the packages you want to use from other libraries in an import statement.

For More Details Click Below :

Package & import

The Package Keyword

Create Your Own Package

Ads