LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Find the Error · Question 3

Error: a long literal assigned to an Integer Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
public class Main {
    public static void main(String[] args) {
        Integer users = 5000L;
        System.out.println(users);
    }
}
  • A 5000 is too large
  • B Boxing converts a long only to Long, never to Integer; use 5000 or declare Long Correct
  • C Integer must be initialised with new
  • D L must be lower case
Correct Answer: Option B

Autoboxing does not combine with narrowing conversions.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links