Java
Programming and Technical
Programming
Program
public void test(int x)
{
int odd = 1;
if(odd) /* Line 4 */
{
System.out.println("odd");
}
else
{
System.out.println("even");
}
}
Which statement is true?
A. Compilation fails.
B. "odd" will always be output.
C. "even" will always be output.
D. "odd" will be output for odd values of x, and "even" for even values.
Read Solution (Total 22)
-
- A.Compilation fails.
Description: Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from int to boolean - 9 years agoHelpfull: Yes(2) No(0)
- compilation fails because in java it is not possible to write any condition as if(odd) where odd is an integer type of variable. This is however only possible using Boolean data type. Because Java is a Strongly typed language
- 9 years agoHelpfull: Yes(1) No(0)
- A.
there is no class - 8 years agoHelpfull: Yes(1) No(0)
- A. int can't be converted to boolean
- 7 years agoHelpfull: Yes(1) No(0)
- odd will be the output because if condition is true
- 9 years agoHelpfull: Yes(0) No(2)
- compilation fails because in java if condition takes only boolean value.
- 9 years agoHelpfull: Yes(0) No(0)
- option : A
- 8 years agoHelpfull: Yes(0) No(0)
- A, Odd type must be boolean
- 7 years agoHelpfull: Yes(0) No(0)
- B
if we pass a value as a condition it is always true. - 7 years agoHelpfull: Yes(0) No(1)
- B
because odd is intialise by 1 always 1
1 is odd - 7 years agoHelpfull: Yes(0) No(1)
- odd will always be output
- 7 years agoHelpfull: Yes(0) No(0)
- error: incompatible types: int cannot be converted to boolean
ans A - 7 years agoHelpfull: Yes(0) No(0)
- Option:A
because if block contain those statement which gives boolean values either true or false - 7 years agoHelpfull: Yes(0) No(0)
- A) Compilation fails is the correct answer because if expects boolean but it gets an integer.
- 6 years agoHelpfull: Yes(0) No(0)
- A is the answer. Compilation fails because java will show error like cannot convert int to boolean
- 6 years agoHelpfull: Yes(0) No(0)
- in c and c++ it works but in java it dnt work.here we declare odd as int so it cannot be boolean..so compilation fails
- 5 years agoHelpfull: Yes(0) No(0)
- a it is a compilation error
- 5 years agoHelpfull: Yes(0) No(0)
- compilation fails because incompatible type (0dd)
- 5 years agoHelpfull: Yes(0) No(0)
- a compilation fail
- 5 years agoHelpfull: Yes(0) No(0)
- The answer is compilation fails because jvm checks line by line there is no class so jvm will give a error .
- 3 years agoHelpfull: Yes(0) No(0)
- odd is "1", so for all the times If will become true and "odd" will be printed.
So Answer is option B. - 2 years agoHelpfull: Yes(0) No(0)
- "odd" will always be output.
- 1 Month agoHelpfull: Yes(0) No(0)
Java Other Question