- Home
- Placement
- Programming
- Operators
- Array
- Data Types
- Functions
- Loop & Control Statements
- Operators & Expressions
- Pointer
- Preprocessor
- Storage Classes
- Structure & Union
- Variables & Constants
- Classes and Objects
- Consructors and Destructors
- Exception handling
- File Handling
- Function Overloading
- Inheritance
- Operator Overloading
- Polymorphism
- Templates
C Language
C++ language
JAVA
-
-
( 1 ) Which of these operators can skip evaluating right hand operand?
- 1) !
- 2) |
- 3) &
- 4) &&
-
Show Answer Report Discussion in forumAnswer : 4) &&
Solution : Operator short circuit and, &&, and short circuit or, ||, skip evaluating right hand operand when output can be determined by left operand alone.
discussion
Answer : 4) &&
-
-
-
( 2 ) What will be the output after compiling and running following code?
public class Test{
public static void main(String... args){
int x =5;
x *= 3 + 7;
System.out.println(x);
}
} - 1) 22
- 2) 50
- 3) 10
- 4) Compilation fails with an error at line 4
-
-
-
( 3 ) What is the output of the following program?
lass Operators1
{
public static void main(String[] args)
{
int a=3, b=6;
System.out.println((~a&b)|(a&~b));
}
} - 1) 5
- 2) 9
- 3) 6
- 4) None of these
-
Show Answer Report Discussion in forumAnswer : 1) 5
Solution : a = 00000011
~a = 11111100 = 00000100 (2's complement)= -4
b = 00000110
----------------
~a&b= 00000100
a = 00000011
~b = 11111001 = 00000111 (2's complement)= -7
----------------
a&~b= 00000001
(~a&b)|(a&~b)
00000100
OR 00000001
-----------
00000101 = 5
discussion
Answer : 1) 5
-
-
-
( 4 ) 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; - 1) 1, 2 & 3
- 2) 1 & 4
- 3) 1, 2, 3 & 4
- 4) 3 & 2
-
Show Answer Report Discussion in forumAnswer : 4) 3 & 2
Solution : 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.
discussion
Answer : 4) 3 & 2
-
-
-
( 5 ) What is the output of the following program?
class Operators1
{
public static void main(String[] args)
{
int i=5,j;
j=i++ + i + ++i;
System.out.println("i="+i);
System.out.println("j="+j);
}
} - 1) 1=7
j=17 - 2) i=6 j=16
- 3) i=7 j=21
- 4) i=7 j=18
-
Show Answer Report Discussion in forumAnswer : 4) i=7 j=18
Solution : Since, i is incremented twice in the statement, i =7
j=18= 5 + 6 + 7
discussion
Answer : 4) i=7 j=18
-
-
-
( 6 ) class Test
{
static int s;
public static void main(String [] args)
{
Test p = new Test();
p.start();
System.out.println(s);
}
void start()
{
int x = 7;
twice(x);
System.out.print(x + " ");
}
void twice(int x)
{
x = x*2;
s = x;
}
} - 1) 7 7
- 2) 7 14
- 3) 14 0
- 4) 14 14
-
Show Answer Report Discussion in forumAnswer : 2) 7 14
Solution : The int x in the twice() method is not the same int x as in the start() method. Start()'s x is not affected by the twice() method. The instance variable s is updated by twice()'s x, which is 14.
discussion
Answer : 2) 7 14
-
-
-
( 7 ) What is the value stored in x in following lines of code?
int x, y, z;
x = 0;
y = 1;
x = y = z = 8; - 1) 0
- 2) 1
- 3) 9
- 4) 7
-
-
-
( 8 ) Which operator is used to invert all the digits in binary representation of a number?
- 1) ~
- 2) >>>
- 3) <<<
- 4) ^
-
-
-
( 9 ) What is the output of this program?
class leftshift_operator {
public static void main(String args[])
{
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2)
System.out.print(i + " " + y);
}
} - 1) 64 0
- 2) 0 64
- 3) 0 256
- 4) 256 0
-
-
-
( 10 ) public class Test{
public static void main(String args[]){
System.out.print(""=="");
System.out.print(" ");
System.out.print("A"=="A");
System.out.print(" ");
System.out.print("a==A");
}
} - 1) "==" A"=="A a==A
- 2) true true false
- 3) true true a==A
- 4) Compilation Fails
-
Show Answer Report Discussion in forumAnswer : 3) true true a==A
Solution :
discussion
Answer : 3) true true a==A
-