Question 1. What is the output of the following question?
Option
A) Error
B) A : a
C) 65 : 97
D) None
Output: C
Explanation : We can use all predefined Java class name and interface name as identifiers.
Question 2. What is the output of the following question?
class Test2 {
public
static void main(String[] args)
{
int if = 65 ;
int else = 97 ;
System.out.println( if + " : " + else );
}
}
|
Option
A) Error
B) A : B
C) 65 : 97
D) None
Output: A
Explanation : We can’t use reserved words as identifiers.
Question 3. What is the output of the following question?
class Test3 {
public
static void main(String[] args)
{
int x = 1 ;
if (x) {
System.out.print( "GeeksForGeeks" );
} else {
System.out.print( "GFG" );
}
}
}
|
Option
A) GeeksForGeeks
B) GFG
C) Error
D) None
Output: C
Explanation :In Java, Compiler gives error – Incompatible types : int can not be converted to boolean type.
But in C or C++ its a valid statement.
Question 4. What is the output of the following question?
class Test4 {
public
static void main(String[] args)
{
double d1 = 123.456 ;
double d2 = 12_3.4_5_6;
double d3 = 12_3.4_56;
System.out.println(d1);
System.out.println(d2);
System.out.println(d3);
}
}
|
Option
A) Error
B) 123.456
12_3.4_5_6
12_3.4_56
C) 123.456
123.456
123.456
D) None
Output: C
Explanation : From (1.7v onwards)we can use ‘_'(under Score) Symbol between digits of numeric literals. See more at Java naming conventions.
Question 5. What is the output of the following question?
class Test2 {
public
static void main(String[] args)
{
int if = 65 ;
int else = 97 ;
System.out.println( if + " : " + else );
}
}
|
Option
A) Error
B) 123.456
12_3.4_5_6
12_3.4_56
C) 123.456
123.456
123.456
D) None
Output: A
Explanation : We can use the ‘_’ (under score) symbol only between the digits. if we are using anywhere else we will get compile time error – Illegal under score.
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!