82). Which of the following can be operands of arithmetic operators?
[A]Numeric
[B]Boolean
[C]Characters
[D]Both Numeric & Characters
Show Answer
Correct Answer: Both Numeric & Characters
Notes:
Answer: d
Explanation: The operand of arithmetic operators can be any of numeric or character type, But not boolean.
83). Modulus operator, %, can be applied to which of these?
[A]Integers
[B]Floating – point numbers
[C]Both Integers and floating – point numbers
[D]None of the mentioned
Show Answer
Correct Answer: Both Integers and floating – point numbers
Notes:
Answer: c
Explanation: Modulus operator can be applied to both integers and floating point numbers.
84). With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
[A]1, 2 & 3
[B] 1 & 4
[C] 1, 2, 3 & 4
[D] 3 & 2
Show Answer
Correct Answer: 1, 2, 3 & 4
Notes:
Answer: c
Explanation: Operator ++ increases value of variable by 1. x = x + 1 can also be written in shorthand form as x += 1. Also x =+ 1 will set the value of x to 1.
85). Decrement operator, −−, decreases the value of variable by what number?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
Show Answer
Correct Answer: 1
Notes:
Answer: a
Explanation: None.
86). Which of these statements are incorrect?
1. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
[A]Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms
[B] Assignment operators run faster than their equivalent long forms
[C]Assignment operators can be used only with numeric and character data type
[D] None of the mentioned
Show Answer
Correct Answer: None of the mentioned
Notes:
Answer: d
Explanation: None.
87). What will be the output of the following Java program?
class increment
{
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
[A]1 1
[B]0 1
[C]1.5 1
[D]1.5 1.0
Show Answer
Correct Answer: 1.5 1
Notes:
Answer: c
Explanation: None
output:$ javac increment.java
$ java increment
1.5 1
88). What will be the output of the following Java program?
class Modulus
{
public static void main(String args[])
{
double a = 25.64;
int b = 25;
a = a % 10;
b = b % 10;
System.out.println(a + " " + b);
}
}
[A]5.640000000000001 5
[B]5.640000000000001 5.0
[C] 5 5
[D]5 5.640000000000001
Show Answer
Correct Answer: 5.640000000000001 5
Notes:
Answer: a
Explanation: Modulus operator returns the remainder of a division operation on the operand. a = a % 10 returns 25.64 % 10 i:e 5.640000000000001. Similarly b = b % 10 returns 5.
output:
$ javac Modulus.java
$ java Modulus
5.640000000000001 5
89). What will be the output of the following Java program?
class increment
{
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
Show Answer
Correct Answer: 32
Notes:
Answer: c
Explanation: Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32.
output:
$ javac increment.java
$ java increment
32
90). Can 8 byte long data type be automatically type cast to 4 byte float data type?
class increment
{
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
[A]True
[B]False
[C]none
[D]none
Show Answer
Correct Answer: true
Notes:
Answer: a
Explanation: Both data types have different memory representation that’s why 8-byte integral data type can be stored to 4-byte floating point data type.
91). What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
b++;
++a;
System.out.println(a + " " + b + " " + c);
}
}
[A]3 2 4
[B] 3 2 3
[C]2 3 4
[D]3 4 4
Show Answer
Correct Answer: 3 4 4
Notes:
Answer: d
Explanation: None.
output:
$ javac Output.java
$ java Output
3 4 4