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.
float a = 1.345f; float b = 567.345678F;
float interest = 24.123456f;
float a = 1.23; //error //can not convert from double to float float b = 1.23F // works double c = 1.567; //works
int a = 987654; //works int b = 9876543210; //Out of range error long c = 9876543210;//Out of range error long d = 9876543210L; //works
char ch='A'; char ch2 = 'b';
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.
Hexadecimal literal uses Base 16 number system.
String name = "JAVA HERO";
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.
float a = 0x3.1p0f; // 3.0625 //3 x p0 = 3 x 2^0 = 3 //(0.1)/16 = 0.0625
float a = 12.0e2f; //1200.0
float a = 100.0e-2f; // 1.0
float a = 123.456e-21f; //1.23456E-19
boolean b= false;
boolean b= 2<4; //2<4 is true;
if(true) { System.out.println("HELLO"); }
What is the output of this Java snippet? int a = 0b111; System.out.println(a);
1x2^2 + 1x2^1 + 1x2^0 1x4 + 1x2 + 1 4 + 2 + 1
boolean a = false;
boolean a = (5>6)||(4>3);
boolean a = 1;
boolean a = 4>3?true:false;
You can not assign an integer value to a boolean data type. Java does not convert integers to boolean true or false.
char a ='a';
char a ="ab";
char a =97;
char a ='\u0123';
A character variable can hold only one letter that can be represented by UTF-16 Unicode internally. Use only single quotes.
String str = "ab"; //works
char ch='\65';
char ch='\142';
char ch='\065';
char ch='142';
char ch='\142'; //works char ch2 = '\97';//9 is not Octal digit
A Unicode character literal in Java is surrounded by a pair of ___? literal = \ua123
char ch='\ua123';
Default values are assigned only to the instance variables.