Java (GATE)

concept based questions

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is the output of the given program?

public class HelloWorld {
 public static void main(String[] args) {
  String s1 = "Welcome to Aliensbrain";
  String s2 = "Welcome to Aliensbrain";
  switch (s1 == s2) {
   default: System.out.println("Bye");
   case 1:
     System.out.println("Hello Italy");
   case 0:
     System.out.println("Hello Paris");
  }
 }
}
  1. Hello ItalyHello Paris
  2. Hello Paris
  3. Bye Hello ItalyHello Paris
  4. Compiler Error
  5. Run time exception
Question 2 Multiple Choice (Single Answer)

What is the output of the given code?

public class HelloWorld {
 public static void main(String[] args) {
  int i = 128 << 2 << 1 << 0;
  switch (i) {
   default: System.out.println("Bye");
   case 128 << 4 << 3 << 2 >> 6:
     System.out.println("Hello Italy");
   case 128 << 4 << 2 << 2 >> 6:
     System.out.println("Hello Paris");
   case 128 << 4 << 4 << 2 >> 3:
     System.out.println("Hello London");
  }
 }
}
  1. ByeHello ItalyHello ParisHello London
  2. Hello ItalyHello ParisHello London
  3. Hello ParisHello London
  4. Hello London
  5. Compiler error
Question 3 Multiple Choice (Single Answer)

Which of the following is not the method of the scanner class object in Java?

  1. Next()
  2. nextLine()
  3. nextInt()
  4. nextChar()
  5. nextLong()
Question 4 Multiple Choice (Single Answer)

What is the output of the given program?

public class HelloWorld {
 public static void main(String[] args) {
  int x = 24;
  int y = 42;
  int z = 37;
  int a = 22;
  System.out.println(x & y | z ^ a);
 }
}
  1. 60
  2. 59
  3. 58
  4. 57
  5. 56
Question 5 Multiple Choice (Single Answer)

What is the output of the given program?

public class HelloWorld {
 public static void main(String[] args) {
  int x = 24;
  int y = 42;
  System.out.println((~x) | (~y));
 }
}
  1. - 25
  2. - 43
  3. - 9
  4. - 6
  5. Compiler error
Question 6 Multiple Choice (Single Answer)

What is the output of the given code?

public class HelloWorld {
 public static void main(String[] args) {
  int x = 24;
  int y = 42;
  int z = 37;
  int a = 22;
  System.out.println(x & y ^ z | x~a);
 }
}
  1. 63
  2. -63
  3. 74
  4. -74
  5. Compiler error
Question 7 Multiple Choice (Single Answer)

What is the output of the given program?

public class Example {
 public static void main(String[] args) {
  String s1 = "Welcome to Aliensbrain";
  String s2 = "Welcome to Aliensbrain";
  if (s1 == s2) // Line 1 
   System.out.println("Equal");
  else System.out.println("Not Equal");
 }
}
  1. Equal
  2. Not Equal
  3. Run time error
  4. Blank output screen
  5. Error at line 1
Question 8 Multiple Choice (Single Answer)

What is the output of the given program?

public class Example {
 public static void main(String[] args) {
   String s1 = new String("Welcome to Aliensbrain");
   String s2 = new String("Welcome to Aliensbrain");
   String s3 =  new String("Welcome to Aliensbrain");
   if (s3 == (s1 == s2)) // Line 1 
      System.out.println("Equal");
   else 
      System.out.println("Not Equal");
 }
}
  1. Equal
  2. Not equal
  3. Blank output
  4. Error at line 1
  5. Run time error
Question 9 Multiple Choice (Single Answer)

What is the output of the given code?

public class HelloWorld {
 public static void main(String[] args) {
  int x = 24;
  int y = 42;
  int z = 37;
  int a = 22;
  System.out.println(x | y | z | a);
 }
}
  1. 64
  2. 59
  3. 62
  4. 63
  5. 77
Question 10 Multiple Choice (Single Answer)

What is the output of the given program?

public class Example {
 public static void main(String[] args) {
   String s1 = new String("Welcome to Aliensbrain");
   String s2 = new String("Welcome to Aliensbrain");
   if (s1 == s2) // Line 1 
      System.out.println("Equal");
   else 
      System.out.println("Not Equal");
 }
}
  1. Equal
  2. Not Equal
  3. Blank screen
  4. Error at line 1
  5. Run time error
Question 11 Multiple Choice (Single Answer)

What is the output of the given code?

public class HelloWorld {
 public static void main(String[] args) {
  int i = 128 << 4 << 3 << 2 >> 6;
  switch (i) {
   default: System.out.println("Bye");
   case 65536:
     System.out.println("Hello Italy");
   case 32:
     System.out.println("Hello Paris");
   case 8 / 2:
     System.out.println("Hello London"); //Line 1 
  }
 }
}
  1. Hello ItalyHello ParisHello London
  2. Bye
  3. ByeHello ItalyHello ParisHello London
  4. Hello ParisHello London
  5. Error at line 1
Question 12 Multiple Choice (Single Answer)

What is the output of the given program?

public class MyClass {
 public static void main(String[] args) {
  System.out.println(128 >> 4 >> 3 >> 2); //Line 1
 }
}
  1. 2
  2. 4
  3. 0
  4. Divide by zero exception
  5. Error at line 1
Question 13 Multiple Choice (Single Answer)

What is the output of the given program?

public class Example {
 public static void main(String[] args) {
   System.out.println(128 << 4 << 3 << 2 >> 6); // Line 1
   }
}
  1. 65536
  2. 1024
  3. 0
  4. Divide by zero exception
  5. Error at line 1