Knowee
Questions
Features
Study Tools

Which of the following will result in a compile-time error? float f = 1.3; char c = 'A'; byte b = 10; boolean b = true;

Question

Which of the following will result in a compile-time error?

  • float f = 1.3;
  • char c = 'A';
  • byte b = 10;
  • boolean b = true;
🧐 Not the exact question you are looking for?Go ask a question

Solution

The first line float f = 1.3; will result in a compile-time error. In Java, by default, any decimal number is treated as a double. So, 1.3 is considered a double value and we are trying to assign it to a float variable which leads to a precision loss. To fix this, you should write it as float f = 1.3f; or float f = (float) 1.3;.

The other lines of code are correct. The second line char c = 'A'; is correct because 'A' is a valid character literal in Java. The third line byte b = 10; is correct because 10 is within the range of byte (-128 to 127). The fourth line boolean b = true; is correct because true is a valid boolean value in Java.

This problem has been solved

Similar Questions

To scan a and b given below, which of the following scanf() statement will you use?#include<stdio.h>float a;

Which of the following data types is not supported by C but is supported by C++?intbooldoublefloat

To print out a and b given below, which of the following printf() statement will you use?float a=3.14:double b=3.14;

Which of the following declaration is not supported by C language?String str;Both “String str;” and “float str = 3e2;”float str = 3e2;char *str;Clear my choice

Which of the following is not a primitive data type in Java?booleancharStringfloat

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.