Thursday, April 9, 2020

Java output questions set - 10


SET-10

1.class test
{
    public static void main(String args[])
   {
 int[] arr = {1,2,3,4};
 call_array(arr[0], arr);
 System.out.println(arr[0] + "," + arr[1]);     
    }
    static void call_array(int i, int arr[])
    {
 arr[i] = 6;
 i = 5;
   } 
}
(A) 1,2
(B) 5,2
(C) 1,6
(D) 5,6

2.public class test
{
 public static void main(String args[])
  {
  int x;
  x = -3 >> 1;
  x = x >>> 2;
  x = x << 1;
   System.out.println(x);
  }
}
(A) 7
(B) 23
(C) 5
(D) 2147483646

3.public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = "abc";
    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}

(A) 1 2
(B) 1 3
(C) 1 4
(D) 2 4

4.public class test {
    public static void main(String args[]) {
    String s1 = "abc";
    String s2 = new String("abc");

    if(s1 == s2)
        System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}
(A) 1 3
(B) 1 4
(C) 2 3
(D) 2 4

5.public class test
{
 public static void main(String args[])
  {
   int i = -1;
   i = i >> 1;
    System.out.println(i);
 }
}
(A) 255
(B) 128
(C) -1
(D) 1

6. Which of the following are legal array declarations
a.int i[5][];
b.int i[][];
c.int []i[];
d.int i[5][5];
e.int[][] a;
(A) a, d, e
(B) b, c, d
(C) b, c, e
(D) a, c, e

7. Which of the following are valid declarations for the main method
a.public static void main(String args[]);
b.public static void main(String []args);
c.final static public void main (String args[]);
d.public static int main(String args[]);
e.public static abstract void main(String args[]);
(A) a, b, c
(B) b, d, e
(C) a, d, c
(D) a, b, e

8.public class example {
  public static void main(String args[]) {
   int x = 0;
   if(x > 0) x = 1;
   switch(x) {
   case 1: System.out.println(1);
   case 0: System.out.println(0);
   case 2: System.out.println(2);
    break;
   case 3: System.out.println(3);
   default: System.out.println(4);
   break;
   }
  }
 }

A.0
B.1
C.2
D.3
E.4
(A) 1, 0, 2
(B) 3, 4
(C) 0, 2
(D) 1

9.String str;
int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
(A) 0
(B) 2
(C) -1
(D) 4

10.public class test {
 public static void main(String args[]) {
  byte x = 3;
   x = (byte)~x;
   System.out.println(x);
  }
 }
(A) 0
(B) 3
(C) -4
(D) none of these

No comments:

Post a Comment

Python Technical Interview Questions

 1)first non repeating character Malayalam y programming p str = "MalayalaM" a = '\0' for c in str:     if str.index(c) ==...