Java Programming MCQ - Operators And Assignments
11. What will be the output of the program?
class Main {
public static void main(String [] args)
{
Main p = new Main();
p.start();
}
void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[0] + a1[1] + a1[2] + " ");
System.out.println(a2[0] + a2[1] + a2[2]);
}
long [] fix(long [] a3)
{
a3[1] = 7;
return a3;
}
}
View Answer
12. What will be the output of the program?
class Main {
public static void main(String [] args)
{
Main p = new Main();
p.start();
}
void start()
{
boolean b1 = false;
boolean b2 = fix(b1);
System.out.println(b1 + " " + b2);
}
boolean fix(boolean b1)
{
b1 = true;
return b1;
}
}
View Answer
13. What will be the output of the program?
class Main {
public static void main(String [] args)
{
Main p = new Main();
p.start();
}
void start()
{
String s1 = "s";
String s2 = fix(s1);
System.out.println(s1 + " " + s2);
}
String fix(String s1)
{
s1 = s1 + "st";
System.out.print(s1 + " ");
return "st";
}
}
View Answer
14. Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
View Answer
15. Predict the output of following Java Program?
class Test {
public static void main(String args[]) {
int x = -4;
System.out.println(x>>1);
int y = 4;
System.out.println(y>>1);
}
}
View Answer
16. 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;
View Answer
17. What is the output of this program?
class Main {
public static void main(String args[])
{
double var1 = 2 + 4;
double var2 = var1 / 4;
int var3 = 2 + 4;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
View Answer
18. What will be the output of the program?
class Main {
public static void main(String [] args)
{
int x=20;
String sup = (x < 15) ? "s" : (x < 22)? "t" : "h";
System.out.println(sup);
}
}
View Answer
19. What will be the output of the program?
class Bitwise
{
public static void main(String [] args)
{
int x = 11 & 9;
int y = x ^ 3;
System.out.println( y | 12 );
}
}
View Answer
20. What is the output of this program?
class increment
{
public static void main(String args[])
{
int g = 5;
System.out.print(++g * 8);
}
}
View Answer
Also check :