LearnFrenzy
Sign in Take a free test

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

Error: an int literal assigned to a Long Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 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) {
        Long population = 1400;
        System.out.println(population);
    }
}
  • A 1400 is too small for Long
  • B An int is boxed only to Integer, and Integer is not a Long; write 1400L Correct
  • C Long cannot hold numbers
  • D population must be primitive
Correct Answer: Option B

long p = 1400; would compile (widening), but Long p = 1400; does not.

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