Home »
Java Aptitude Que. & Ans.
Java Operators Aptitude Questions and Answers (page 2)
Java Operators Aptitude Questions and Answers (page 2): This section provides you Java Operators related Aptitude Questions and Answers with multiple choices. Here, You will get solution and explanation of each question.
List of Java Operators Aptitude Questions and Answers
6)
What will be the output of following program?
class Opr
{
public static void main(String args[])
{
System.out.print( ((true && true) || false) );
}
}
- Error
- false
- true
- None of these
7)
What will be the output of following program?
class Opr
{
public static void main(String args[])
{
int a,i;
i=10;
a=a+i;
System.out.print(a);
}
}
- 10
- Garbage
- Error
- None of these
Correct Answer: 3
ERROR: The local variable a may not have been initialized.
Variable must be initialized before using it. In the statement a=a+i; you are adding value of i in the variable a and a is not initialized.
8)
What will be the output of following program?
public class Opr {
public static void main(String[] args) {
int a=0;
System.out.print((a==true)? "Hello": "Hi");
}
}
- Hello
- Hi
- Error
- Null
Correct Answer: 3
ERROR: The operator == is undefined for the argument type(s) char, boolean.
In Java programming Language, Operator == will work with true/false (boolean values) and here a is not a boolean value. Hence ERROR will be occurred.
9)
What will be the output of following program?
public class Opr {
public static void main(String[] args) {
System.out.print(0x000A + 0b1010 + 0xff);
}
}
- Error
- 255
- 20ff
- 275
Correct Answer: 4
275
Here, 0x000A (Hex) is 10, 0b1010 (Binary) is 10 and 0xff (hex) is 255.
10)
What will be the output of following program ?
class Opr
{
public static void main(String [] args)
{
System.out.println( (10|5)+"-"+ (10|6));
}
}
- 15-14
- 10-10
- 15-16
- 15-15
Correct Answer: 1
15-14
Consider the binary of 10, 5 and 6. Solve 10|5 = Using Binary (1010|0101 = 1111 = 15) and 10|6 = Using Binary (1010|0110 = 1110 = 14).
Page 1