41. What will be the output for the below code?
class A{
public void printValue(){
System.out.println("A");
}
}
class B extends A{
public void printValue(){
System.out.println("B");
}
}
public class Test{
public static void main(String... args){
A b = new B();
newValue(b);
}
public static void newValue(A a){
if(a instanceof B){
((B)a).printValue();
}
}
}
class A{
public void printValue(){
System.out.println("A");
}
}
class B extends A{
public void printValue(){
System.out.println("B");
}
}
public class Test{
public static void main(String... args){
A b = new B();
newValue(b);
}
public static void newValue(A a){
if(a instanceof B){
((B)a).printValue();
}
}
}
42. Determine output:
public class Test{
static int i = 5;
public static void main(String... args){
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
System.out.println(++i+i++);
}
}
public class Test{
static int i = 5;
public static void main(String... args){
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
System.out.println(++i+i++);
}
}
43. What will be the output of the following Java code?
class operators
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
int var3;
var3 = ++ var2 * var1 / var2 + var2;
System.out.print(var3);
}
}
class operators
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
int var3;
var3 = ++ var2 * var1 / var2 + var2;
System.out.print(var3);
}
}
44. Which of these are selection statements in Java?
45. On applying Left shift operator, <<, on integer bits are lost one they are shifted past which position bit?
46. 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. x++;
2. x = x + 1;
3. x += 1;
4. x =+ 1;
47. Which of the following can be operands of arithmetic operators?
48. What will be the output of the following Java program?
class jump_statments
{
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y)
{
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}
class jump_statments
{
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y)
{
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}
49. Which operator is used to invert all the digits in a binary representation of a number?
50. What will be the output of the following Java 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);
}
}
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);
}
}
Read More Section(Operators)
Each Section contains maximum 100 MCQs question on Operators. To get more questions visit other sections.