Which of the following is the correct way to declare a boolean variable named isJavaFun and initialize it to true in Java?
A. boolean isJavaFun = true
B. bool isJavaFun = true
C. boolean = true
D. bool = true
Answer: Option A
Solution(By Examveda Team)
The correct answer is Option A: boolean isJavaFun = true.In Java, the correct way to declare a boolean variable named isJavaFun and initialize it to true is by using Option A.
Here's the breakdown:
Option A: boolean isJavaFun = true - This is the correct way to declare a boolean variable named isJavaFun and initialize it to true in Java.
Option B: bool isJavaFun = true - This is not the correct syntax in Java. The correct keyword for declaring a boolean variable is boolean, not bool.
Option C: boolean = true - This is not a valid way to declare a boolean variable in Java. It lacks the variable name.
Option D: bool = true - This is also not a valid way to declare a boolean variable in Java. It lacks the variable name, and the keyword bool is not used in Java.
So, the correct way to declare a boolean variable named isJavaFun and initialize it to true in Java is boolean isJavaFun = true.
Related Questions on Data Types and Variables
What is the maximum value that can be stored in a byte variable in Java?
A. 127
B. 255
C. 32767
D. 64
What is the default value of an int variable in Java if it's not explicitly initialized?
A. 0
B. 1
C. -1
D. Null
Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var
Join The Discussion