In this tutorials we will discussed more about variables in java programming of Instance Variables.
Types of variables:
Class Or StaticInstance
Local
Parameters Or Arguments
What we need before start the code, I'm using as mention below and already installed in my system:
1. JDK1.6 or +
2. Eclipse
3. Windows OS
4. Basic knowledge of java
Let's start:
Verify the JDK installation
Open the command prompt and verify the java installation
Type the
C:\>javac -version
javac 1.7.0_25
C:\>java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)
Now java installation got verified, as installed JDK1.7.0_25
Verify the Eclipse installation
Go the the installation directory of eclipse and click on the eclipse.exe
Create the new java project in Eclipse
Open the eclipse
File
New
Java project
Type the project name: Variables_In_Java_Programming
Next
Finish
Create the InstanceVariablesInJava.java file
Right click on the src created under project Variables_In_Java_Programming
New
Class
Type the name of class: InstanceVariablesInJava
Type the package name: com.variables.atozexamples
Finish
package
com.variables.atozexamples;
public class
InstanceVariablesInJava {
// Declared and
instantiated with 100 value
// This is also
called as filed.
private int iInstanceVariables;
public
InstanceVariablesInJava() {
// TODO Auto-generated
constructor stub
}
public
InstanceVariablesInJava(int i, int b) {
// TODO Auto-generated
constructor stub
this.iInstanceVariables = i;
}
public
InstanceVariablesInJava(int iInstanceVariables) {
// TODO Auto-generated
constructor stub
this.iInstanceVariables = iInstanceVariables;
}
public static void main(String[] args) {
// Creating the new
object of InstanceVariablesInJava class.
InstanceVariablesInJava
objInstanceVariablesInJava = new
InstanceVariablesInJava();
System.out.println("Output of
iInstanceVariables = " + objInstanceVariablesInJava.iInstanceVariables);
//System.out.println("Compile
time error "+ iInstanceVariables);
// Creating the new
object of InstanceVariablesInJava class.
InstanceVariablesInJava
objOne = new
InstanceVariablesInJava(3000);
System.out.println("Output of
iInstanceVariables = " + objOne.iInstanceVariables);
// Creating the new
object of InstanceVariablesInJava class.
InstanceVariablesInJava
objTwo = new
InstanceVariablesInJava(3999);
System.out.println("Output of
iInstanceVariables = " + objTwo.iInstanceVariables);
}
}
All about Instance variables in java programming.
No comments:
Post a Comment