Test Series - java

Test Number 27/64

Q: You can nest one Java Ternary operator inside another Ternary operator. State TRUE or FALSE.
A. FALSE
B. TRUE
C. None
D. FALSE or TRUE
Solution: no solution
Q: What is the output of the code snippet with the ternary operator?
int p=5;
System.out.print("Hello ");
(p<6)?5:6;
A. Hello 5
B. Hello 6
C. Hello
D.  Compiler error
Solution: Unresolved compilation problems:

The left-hand side of an assignment must be a variable
Q: What is the output of the Java code snippet with Ternary operator?
int num = false?10:20;
System.out.println(num);
A. 10
B. 20
C. 0
D. Compiler error
Solution: no solution
Q: What is the output of the Java code snippet with Ternary operator?
String name = "java";
int marks = name == "java"?10:20;
System.out.println("Marks=" + marks);
A. marks=0
B. marks=10
C. marks=20
D. Compiler error
Solution: no solution
Q: What is the output of the Java code snippet with a Ternary operator?
String name = "cat";
int marks = name == "Cat"?10:20;
System.out.println("Marks=" + marks);
A. Marks=0
B. Marks=10
C. Marks=20
D. Compiler error
Solution: no solution
Q: What is the output of the Java code snippet with a Ternary operator?
String name1 = "pen";
String name2 = "pen";
int marks = name2.equals(name1)?50:80;
System.out.println("Marks=" + marks);
A. Marks=0
B. Marks=50
C. Marks=80
D. Compiler error
Solution: no solution
Q: What is the output of the Java code snippet with a Ternary operator?
void show()
{
  int num = true ? getNumber() : 20;
  System.out.print("TOMATO=" + num);
}
	
void getNumber()
{
  System.out.print(30);
}
A. TOMATO=0
B. TOMATO=20
C. TOMATO=30
D. Compiler error
Solution: The "void" type is not allowed as an Operand of a Ternary or Conditional operator.
Q: What is the output of Java code snippet with a Ternary operator or Conditional operator?
void show()
{
  String name = true ? getName() : "FRANCE";
  System.out.print(name);
}

void getName()
{
  System.out.print("ENGLAND");
}
A. Empty string
B. FRANCE
C. ENGLAND
D. Compiler error
Solution: The void functions are not allowed inside a Ternay operator statement.
Q: What is the output of Java code snippet with a Ternary operator?
String forest = null;
String output = forest != null ? "Goblin" : "Amazon";
System.out.println(output);
A. null
B. Goblin
C. Amazon
D. Compiler error
Solution: no solution
Q: What is the output of the Java code snippet below?
int a = 20, b=30;
int total = a>10&&b<10?65:75;
System.out.println(total);
A. 0
B. 65
C. 75
D. Error: The left-hand side of an assignment must be a variable
Solution: no solution

You Have Score    /10