More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. member variable are loaded into heap, so they are initialized with default values when an instance of a class is created. In case of local variables, they are stored in stack until they are being used.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The default value of the boolean type is false.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  java   data type   boolean   initialization   default object construction   default constructor   default value
Q4. What will be the output of following code ?
public static void main(String[] args) { int x = 10; int y; if (x < 100) y = x / 0; if (x >= 100) y = x * 0; System.out.println("The value of y is: " + y); }
Ans. The code will not compile raising an error that the local variable y might not have been initialized. Unlike member variables, local variables are not automatically initialized to the default values for their declared type.
Help us improve. Please let us know the company, where you were asked this question :