Questions on operators in java questions and answers
(1)
public class BitwiseOpe {
public static void main(String[] args) {
int a=010;
Integer b=10;
double d=~a|(b=a)<<2+b;
System.out.print(d);
}
}
What will output when you compile and run the above code?
(a)32768.0
(b)-9.0
(c)1.0
(d)Compiler error
Answer: (b)
(2)
public class BitwiseOpe {
public static void main(String[] args) {
int a=010;
char c='a';
double d=-c%-2.D+(a^=2)-2;
System.out.print(d);
}
}
What will output when you compile and run the above code?
(a)-7.0
(b)-8.0
(c)-9.0
(d)Compiler error
Answer: (a)
(3)
public class BitwiseOpe {
public static void main(String[] args) {
int a=010;
char c='0';
double d=++a + 2.0^c;
System.out.print(d);
}
}
What will output when you compile and run the above code?
(a)61.0
(b)59.0
(c)59.000000
(d)Compiler error
Answer: (d)
(4)
public class BitwiseOpe {
public static void main(String[] args) {
int j=10;
j&=j|3;
System.out.print(j);
}
}
What will output when you compile and run the above code?
(a)11
(b)10
(c)true
(d)Compiler error
Answer: (b)
(5)
public class BitwiseOpe {
public static void main(String[] args) {
byte a=010,b=-12;
int c=a|b;
System.out.print(c);
}
}
What will output when you compile and run the above code?
(a)12
(b)-4
(c)-12
(d)Compiler error
Answer: (b)
(6)
public class LogicalOpe {
public static void main(String[] args) {
int a=5;
if(a>2||a++<10)
System.out.print(a);
else
System.out.print(--a);
}
}
What will output when you compile and run the above code?
(a)6
(b)5
(c)4
(d)Compiler error
Answer: (b)
(7)
public class LogicalOpe {
public static void main(String[] args) {
int a=5;
if(a>6&&a++<10)
System.out.print(a);
else
System.out.print(--a);
}
}
What will output when you compile and run the above code?
(a)4
(b)5
(c)6
(d)Compiler error
Answer: (a)
(8)
public class LogicalOpe {
public static void main(String[] args) {
int a=010;
Integer b=10;
if(true&&++a<++b||++a>--b)
System.out.print(a);
else
System.out.print(b);
}
}
What will output when you compile and run the above code?
(a)8
(b)9
(c)10
(d)Compiler error
Answer: (b)
(9)
class LogicalOperator {
public static void main(String[] args) {
byte a=10,b=0,c;
c=a&&b + a||b;
System.out.println(c);
}
}
What will output when you compile and run the above code?
(a)1
(b)0
(c)2
(d)Compiler error
Answer: (d)
(10)
public class ArithmeticlOpe {
public static void main(String[] args) {
float f=5f;
f=f%2;
System.out.print(f);
}
}
What will output when you compile and run the above code?
(a)1.0
(b)1.000000
(c)Run time exception
(d)Modular division is not applicable for floating point number,
Compiler error
Answer: (a)
(11)
public class ArithmeticlOpe {
public static void main(String[] args) {
byte a=6;
int b=6;
int c=a>>>2+b>>>2;
System.out.println(c);
}
}
What will output when you compile and run the above code?
(a)0
(b)2
(c)12
(d)Compiler error
Answer: (a)
(12)
public class ArithmeticlOpe {
public static void main(String[] args) {
byte a=6;
int b=6;
int c=(a>>>2)+b>>2;
System.out.println(c);
}
}
What will output when you compile and run the above code?
(a)1
(b)2
(c)12
(d)Compiler error
Answer: (a)
(13)
class ArithmeticlOperator {
public static void main(String[] args) {
byte a=-10;
int b=a%-3;
System.out.println(b);
}
}
What will output when you compile and run the above code?
(a)1
(b)3
(c)-1
(d)Compiler error
Answer: (c)
(14)
public class RelationalOpe {
public static void main(String[] args) {
Integer i=011;
if(false==false)
System.out.println(i);
else
System.out.println(i++);
}
}
What will output when you compile and run the above code?
(a)9
(b)10
(c)11
(d)Compiler error
Answer: (a)
(15)
public class RelationalOpe {
public static void main(String[] args) {
Boolean B=25>=031;
boolean b=true^true;
if(b!=B)
System.out.println(B);
else
System.out.println(b);
}
}
What will output when you compile and run the above code?
(a)true
(b)false
(c)1
(d)Compiler error
Answer: (a)
(16)
public class Ope {
public static void main(String[] args) {
int a=5;
if(a++)
System.out.println(a);
else
System.out.print(--a);
}
}
What will output when you compile and run the above code?
(a)5
(b)4
(c)6
(d)Compiler error
Answer: (d)
(17)
public class UnaryOperator {
public static void main(String[] args) {
float f=3.0f;
f/=f*(float)true;
System.out.print(f);
}
}
What will output when you compile and run the above code?
(a)1.0
(b)Infinity
(c)NaN
(d)Compiler error
Answer: (d)
(18)
public class UnaryOperator {
public static void main(String[] args) {
Double d=1.5D;
d+=d++ + ++d;
System.out.print(d);
}
}
What will output when you compile and run the above code?
(a)8.0
(b)6.5
(c)4.6
(d)Unary increment operators in not suitable for double type
data, Compiler error
Answer: (b)
(19)
public class UnaryOperator {
public static void main(String[] args) {
Double d=1.33D;
d=d+++d;
System.out.print(d);
}
}
What will output when you compile and run the above code?
(a)2.66
(b)3.66
(c)2.67
(d)Ambiguous unary increment operator, Compiler error
Answer: (b)
(20)
public class UnaryOperator {
public static void main(String[] args) {
int j=5,k;
k=++j + ++j + ++j;
System.out.print(k);
}
}
What will output when you compile and run the above code?
(a)24
(b)21
(c)18
(d)Local variable must be initialized, Compiler error
Answer: (b)
Java questions of data types and answer
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
Java questions of data types and answer
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
No comments:
Post a Comment