public
class Test {
public
static void main(String[] args)
{
int X
10;
if (x) {
System.out.println("HELLO
} else {
System.out.println("BYE" );
}
}
}
Answers
Answer:
Data StructuresAlgorithmsInterview PreparationTopic-wise PracticeC++JavaPythonCompetitive ProgrammingMachine LearningHTMLSDE SheetPuzzlesGFG SchoolProjects
▲
Related Articles
Output of Java Programs | Set 48 (Static keyword)Output of Java Programs | Set 45 (static and instance variables)Output of Java Programs | Set 44 (throws keyword)Output of Java Programs | Set 39 (throw keyword)Output of Java Programs | Set 40 (for loop)Output of Java Programs | Set 36 (do-while loop)Output of Java Programs | Set 35 (Decision Making)Java Tricky Output QuestionsOutput of Java Program | Set 1Output of Java Program | Set 2Output of Java Program | Set 3Output of Java Program | Set 4Output of Java program | Set 5Output of Java Program | Set 6Output of Java Program | Set 7Output of Java Program | Set 8Output of Java Program | Set 9Output of Java programs | Set 10 (Garbage Collection)Output of Java Program | Set 11Output of Java Programs | Set 12Output of Java programs | Set 13 (Collections)Output of Java Programs | Set 14 (Constructors)Output of Java Programs | Set 37 (If-else)Output of Java Programs | Set 38 (Arrays)Output of Java Programs | Set 47 (Arrays)Output of C Programs | Set 9Arrow operator -> in C/C++ with ExamplesOutput of C Programs | Set 1delete keyword in C++
Output of Java Programs | Set 35 (Decision Making)
Difficulty Level : EasyLast Updated : 20 Sep, 2017
Prerequisite: Decision Making in Java
Predict the Output of the following programs
1. What will be the output of the following program?
public
class Test {
public
static void main(String[] args)
{
int x = 10;
if (x) {
System.out.println("HELLO GEEKS");
} else {
System.out.println("BYE");
}
}
}
Options:
1. HELLO GEEKS
2. Compile time error
3. Runtime Error
4. BYE
Output:
The answer is option (2
Explanation:
The argument of if statement should be Boolean type. By mistake if we are trying to provide any other data type then we will get compile-time error saying incompatible types. Here the argument is of int type, therefore we will get compile time error saying error: incompatible types: int cannot be converted to Boolean