Primitives- Numeric data types QuizS2C Home « Primitives- Numeric data types Quiz

Fundamentals Quiz 4

The quiz below tests your knowledge of the material learnt in Fundamentals - Lesson 5 - Primitives - Numeric data types.

Question 1 : What will be returned from the following code?

long aLong = 3672543567;
System.out.println("aLong = " + aLong);?
- We get a compiler error. When we pass a literal value to a long we need to append l or L to it or the compiler inteprets it as an integer. Because an integer has a range of -2,147,483,648 to 2,147,483,647 the number is out of range even though we passed it to a long primitive type.
Question 2 : An int can fit into a short?
- Integer types can fit into larger integer types but not smaller. So an int will not fit into a short.
Question 3 : What other integer types can a byte fit into?
- A byte can fit into a short, an int or a long
Question 4 : What are the two floating point primitive types?
- The two floating point primitive types are double and float.
Question 5 : Will the following code compile?

short s 65; byte b= 65; int i = s + b;
- Variable i is dynamically initialized at runtime from s and b so is fine - <code>short s 65; byte b= 65; int i = s + b;</code>.
Question 6 : What other integer types can a short fit into?
- A short can fit into an int and a long
Question 7 : What happens when we compile the following statement?

float f = 16.54;
- Doesn't compile as the compiler thinks we are passing a double to a float - <code>float f = 16.54;</code>.
Quiz Progress Bar Please select an answer


What's Next?

The next quiz on Java is about the method scope and the Stack.