Default value Of int In Java

We will see what is default value of int in java in tutorial . We will write a java program to find java int default value. In this example we will create a unassigned int variable then print value of this variable .

Note : The Default value of int in java is 0.

Program to find the default value of int in java

We check int default value java in this example. We create a unassigned variable(defaultInt) , then print it’s value .

public class DefaultIntValue {

	int defaultInt;

	public static void main(String[] args) {
		DefaultIntValue defaultIntValue = new DefaultIntValue();
		defaultIntValue.printIntDefaultValues();
	}

	public void printIntDefaultValues() {
		// print default value of int
		System.out.println("Default value of boolean: " + defaultInt);
	}

}

Output :

Default value of boolean: 0

This examples clears that default value of int in java is 0 .

Let’s be sure about it . We will create few more unassigned int variables and print value of these unassigned int variables .

public class DefaultIntValue2 {
	
	int defaultInt1;
	int defaultInt2;

	public static void main(String[] args) {
		DefaultIntValue2 defaultIntValue2 = new DefaultIntValue2();
		defaultIntValue2.printIntDefaultValues();
	}

	public void printIntDefaultValues() {
		//print default value of int
		System.out.println("Default value of int: " + defaultInt1);
		System.out.println("Default value of int: " + defaultInt2);
		
	}
	

}

Output :

Default value of int: 0
Default value of int: 0

Now it is verify that int default value java is 0 .

In this tutorial we learned java int default value is zero(0). You can see more java program for practice .

Leave a Reply

Your email address will not be published. Required fields are marked *

40 − = 38