Value boolean type automatically initialized

Value boolean type automatically initialized

Answer : “false” 

Note : If you define boolean variable in same class and try to use it then you will see compile time exception : The local variable string may not have been initialized . To use locally you must initialize it. Please see example below:

package com.javahonk.stringtest;

public class BooleanTest {

    public static void main(String[] args) {

	//Example 1
	TopClass topClass=new TopClass();
	System.out.println(topClass.isTest());

	//Example 2
	boolean value; 
	//System.out.println(value);//Compile time exception.

    }
}

class TopClass {
    private boolean test;

    public boolean isTest() {
        return test;
    }

    public void setTest(boolean test) {
        this.test = test;
    }

}

 

Output:

Value boolean type automatically initialized

Leave a Reply

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