Line 1 : int x = Integer.parseInt("5"); Line 2 : float pi=Float.parseFloat("3.14"); Line 3 : boolean status=Boolean.parseBoolean("TRUE");Line 4 : char c = new Character("X");Which of the above lines can cause compilation error?Select one:a.Line 4b.Line 2c.Line 1d.Line 3
Question
Line 1 : int x = Integer.parseInt("5"); Line 2 : float pi=Float.parseFloat("3.14"); Line 3 : boolean status=Boolean.parseBoolean("TRUE");Line 4 : char c = new Character("X");Which of the above lines can cause compilation error?Select one:a.Line 4b.Line 2c.Line 1d.Line 3
Solution
The answer is a. Line 4. The Character class in Java does not have a constructor that takes a String. It only has a constructor that takes a char. So, trying to create a new Character with a String will result in a compilation error.
Similar Questions
public class Main { public static void main(String args[]) { blank }}Drag and drop the correct code which will cause NumberFormatException when the above code is compiled.int x = Integer.parseInt("5.6"); double pi=Double.parseDouble("3.14"); boolean status=Boolean.parseBoolean("TRUE");
Which of the following will result in a compile-time error? float f = 1.3; char c = 'A'; byte b = 10; boolean b = true;
What is the output of Integer.parseInt("10", 2)? _____A. 1;B. 2; C. 10;D. Invalid statement;
This code produces an error message. Where will the error occur, and why?1 bool a = 1;2 int b = 2 + 4;3 float c = 4;4 cout<<a + b<<endl;
Which of the following Java program statements gives a compilation error?1. public class MyProgram {2. public static void main (String[] args) {3. int x = 5;4. int y = 7;5. product = x * y;6. System.out.println(product);7. }8. }Group of answer choicesNone. The program is correct.Line 2Line 5Line 6
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.