Java Literals MCQ Questions and Answers 2

Study and learn Java MCQ questions and answers on Literals or Constants. Literals are of type Integer (Decimal, Octal, Hexadecimal and Binary), Real Number (float, double), Character and String. Attend job interviews easily with these MCQs.

Go through Java Basic Theory Notes on Literals before studying these questions.



1) What is the suffix used to represent a floating point number in Java?
A) r or R
B) f or F
C) fl or FL
D) None of the above
Answer [=]
Answer[=]
2) What is the precision after decimal points offered by a float data type in Java?
A) 3 digits
B) 6 digits
C) 10 digits
D) 15 digits
Answer [=]
Answer[=]
3) A real number literal for floating point literal with a missing f or F suffix represents which data type?
A) double
B) float
C) long
D) int
Answer [=]
Answer[=]
4) What is the suffix used to convert an int literal to long literal in Java?
A) 0l or 0L
B) l or L
C) i or I
D) 0x or 0X
Answer [=]
Answer[=]
5) A character literal in Java is enclosed within a pair of ___?
A) Square brackets
B) Double Quotes
C) Single Quotes
D) Exclamations
Answer [=]
Answer[=]
6) Which version of Java started offering unsigned int and unsigned long to represent very long numbers?
A) JDK 5
B) JDK 6
C) JDK 7
D) JDK 8
Answer [=]
Answer[=]
7) Choose a correct statement about Java literal types.
A) Decimal literal uses Base 10 number system.
B) Binary literal uses Base 2 number system.
C) Octal literal uses Base 8 number system.
D) All the above
Answer [=]
Answer[=]


 

8) A String literal in Java is surrounded by a pair of _____?
A) Braces
B) Single Quotes
C) Double Quotes
D) Exclamations
Answer [=]
Answer[=]
9) Which among the following is not a primitive data type in Java?
A) char
B) String
C) byte
D) short
Answer [=]
Answer[=]
10) Which version of Java introduced Hexadecimal floating point numbers?
A) JDK 5
B) JDK 6
C) JDK 7
D) JDK 8
Answer [=]
Answer[=]
11) What are the two floating point notations in Java language?
A) Exponential e or E (10^a)
B) Exponential p or P (2^a)
C) A and B
D) None of the above
Answer [=]
Answer[=]
12) Choose the correct implementation of floating point literals in the exponential form in Java.
A)
float a = 12.0e2f; //1200.0
B)
float a = 100.0e-2f; // 1.0
C)
float a = 123.456e-21f;
//1.23456E-19
D) All the above
Answer [=]
Answer[=]
13) Choose the correct usage of boolean literal in the options below.
A)
boolean b= false;
B)
boolean b= 2<4;
//2<4 is true;
C)
if(true)
{ System.out.println("HELLO"); }
D) All the above
Answer [=]
Answer[=]
14)
What is the output of this Java snippet?
int a = 0b111;
System.out.println(a);
A) 111
B) 7
C) 8
D) Compiler error
Answer [=]
Answer[=]


 

15) Choose the wrong Java code statement below.
A)
boolean a = false;
B)
boolean a = (5>6)||(4>3);
C)
boolean a = 1;
D)
boolean a = 4>3?true:false;
Answer [=]
Answer[=]
16) Choose the wrong Java code statement below.
A)
char a ='a';
B)
char a ="ab";
C)
char a =97;
D)
char a ='\u0123';
Answer [=]
Answer[=]
17) Choose the wrong representation of a character literal in Octal notation in Java.
A)
char ch='\65';
B)
char ch='\142';
C)
char ch='\065';
D)
char ch='142';
Answer [=]
Answer[=]
18)
A Unicode character literal in Java is surrounded by a pair of ___?
literal = \ua123
A) Single Quotes
B) Double Quotes
C) Exclamations
D) Backslashes
Answer [=]
Answer[=]
19) What is the default boolean literal assigned to a boolean variable in Java?
A) true
B) false
C) undefined
D) None of the above
Answer [=]
Answer[=]
20) What is the default character literal value assigned to a char variable in Java?
A) 'a'
B) '0'
C) '\u0000'
D) 0
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.