LearnFrenzy
Sign in Take a free test

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

Error: assigning null to an int Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 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) {
        int stock = null;
        System.out.println(stock);
    }
}
  • A stock must be final
  • B A primitive int cannot hold null; use Integer if "no value" is needed, or a real number such as 0 Correct
  • C println cannot print int
  • D null must be in quotes
Correct Answer: Option B

javac: "incompatible types: cannot be converted to int".

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