Test Series - java

Test Number 10/64

Q: 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
Solution: float a = 1.345f;
float b = 567.345678F;
Q: 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
Solution: float interest = 24.123456f;
Q: 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
Solution: float a = 1.23; //error
//can not convert from double to float

float b = 1.23F // works
double c = 1.567; //works
Q: 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
Solution: int a = 987654; //works
int b = 9876543210; //Out of range error
long c = 9876543210;//Out of range error
long d = 9876543210L; //works
Q: 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
Solution: You have to use Object version of int and long namely Integer and Long to avail the feature. Using primitive data types, you can not create an unsigned int or unsigned long.
Q: 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
Solution: Hexadecimal literal uses Base 16 number system.
Q: A String literal in Java is surrounded by a pair of _____?
A. Braces
B. Single Quotes
C. Double Quotes
D. Exclamations
Solution: String name = "JAVA HERO";
Q: Which among the following is not a primitive data type in Java?
A. char
B. String
C. byte
D. short
Solution: A string is a Class that can handle a string of characters or a group of characters. If the name of the type starts with an Uppercase letter, it is a Class. So it is non-primitive.
Q: Which version of Java introduced Hexadecimal floating point numbers?
A. JDK 5
B. JDK 6
C. JDK 7
D. JDK 8
Solution: float a = 0x3.1p0f; // 3.0625
//3 x p0 = 3 x 2^0 = 3
//(0.1)/16 = 0.0625 

You Have Score    /9