• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

50 Java Language MCQs with Answers

Question 11

Output of following Java program? C
class Test
{
    public static void main (String[] args) 
    {
        int arr1[] = {1, 2, 3};
        int arr2[] = {1, 2, 3};
        if (arr1 == arr2) 
            System.out.println(\"Same\");
        else
            System.out.println(\"Not same\");
    }
}
  • Same
  • Not Same

Question 12

Java
class Test {
   public static void main(String args[]) {
     int arr[] = new int[2];  
     System.out.println(arr[0]);
     System.out.println(arr[1]);
   }
}
  • 0
    0
  • garbage value
    garbage value
  • Compiler Error
  • Exception

Question 13

Java
class Test
{
    public static void main (String[] args) 
    {
        int arr1[] = {1, 2, 3};
        int arr2[] = {1, 2, 3};
        if (arr1.equals(arr2))
            System.out.println(\"Same\");
        else
            System.out.println(\"Not same\");
    }
}
  • Same
  • Not same

Question 14

Predict the output? Java
// file name: Main.java
public class Main {
    public static void main(String args[]) {
       int arr[] = {10, 20, 30, 40, 50};
       for(int i=0; i < arr.length; i++)
       {
             System.out.print(\" \" + arr[i]);              
       }
    }
}
  • 10 20 30 40 50
  • Compiler Error
  • 10 20 30 40

Question 15

Which of the following is FALSE about arrays in Java?

  • A java array is always an object

  • Length of array can be changed after creation of array

  • Arrays in Java are always allocated on heap

Question 16

C
class Main {   
   public static void main(String args[]) {      
         int t;      
         System.out.println(t); 
    }   
}
  • 0
  • garbage value
  • compiler error
  • runtime error

Question 17

Predict the output of following Java program. C
class Test { 
    public static void main(String[] args) { 
      for(int i = 0; 0; i++) 
      { 
          System.out.println(\"Hello\"); 
          break; 
      } 
    } 
} 
  • Hello
  • Empty Output
  • Compiler error
  • Runtime error

Question 18

Predict the output of the following program. Java
 class Test
{
    public static void main(String[] args)
    {
        Double object = new Double(\"2.4\");
        int a = object.intValue();
        byte b = object.byteValue();
        float d = object.floatValue();
        double c = object.doubleValue();

        System.out.println(a + b + c + d );

    }
}
  • 8
  • 8.8
  • 8.800000095367432

Question 19

Which of the following statements is/are TRUE regarding JAVA ? (a) Constants that cannot be changed are declared using the ‘static’ keyword. (b) A class can only inherit one class but can implement multiple interfaces.
  • Only (a) is TRUE.
  • Only (b) is TRUE.
  • Both (a) and (b) are TRUE.
  • Neither (a) nor (b) are TRUE.

Question 20

JAVA
class Test
{
    static int a;
    
    static
    {
        a = 4;
        System.out.println (\"inside static block\\n\");
        System.out.println (\"a = \" + a);
    }
    
    Test()
    {
        System.out.println (\"\\ninside constructor\\n\");
        a = 10;
    }
    
    public static void func()
    {
        a = a + 1;
        System.out.println (\"a = \" + a);
    }
    
    public static void main(String[] args)
    {

        Test obj = new Test();
        obj.func();

    }
}
 
  • inside static block
    a = 4
    inside constructor
    a = 11
  • Compiler Error
  • Run Time Error
  • inside static block
    a = 4
    inside constructor
    a = 5
    
  • inside static block
    a = 10
    inside constructor
    a = 11
    

There are 50 questions to complete.

Last Updated :
Take a part in the ongoing discussion