github

Made bySaurav Hathi

MCQ Test Java: Miscellaneous

Q1:

What is the output of this java program?

class variable_scope

{

public static void main(String args[])

{

int x;

x = 5;

{

int y = 6;

System.out.print(x + " " + y);

}

System.out.println(x + " " + y);

}

}

Tags:
Section:
Core Programming
Options:
Q2:

What will be the output of this java program?

class BitShift

{

public static void main(String [] args)

{

int x = 0x80000000;

System.out.print(x + " and  ");

x = x >>> 31;

System.out.println(x);

}

}

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this 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);

}

}

Tags:
Section:
Core Programming
Options:
Q4:

Which one of the following classes contains both date and time in java?

Tags:
Section:
Core Programming
Options:
Q5:

Which of these packages contains all the classes and methods required for even handling in Java?

Tags:
Section:
Core Programming
Options:
Q6:

Which of these packages contains all the Java’s built in exceptions?

Tags:
Section:
Core Programming
Options:
Q7:

Which of the following is a correct way of importing an entire package ‘pkg’ in java?

Tags:
Section:
Core Programming
Options:
Q8:

Which of the following is incorrect statement about packages in java?

Tags:
Section:
Core Programming
Options:
Q9:

What will be the output of this java program?

class display

{

    int x;

    void show()

    {

        if (x > 1)

            System.out.print(x + " ");

    }

}

class packages

{

    public static void main(String args[])

    {

        display[] arr=new display[3];

        for(int i=0;i<3;i++)

            arr[i]=new display();

        arr[0].x = 0;     

        arr[1].x = 1;

        arr[2].x = 2;

        for (int i = 0; i < 3; ++i)

            arr[i].show();

     }

}

Tags:
Section:
Core Programming
Options:
Q10:

What will this java code print?

int arr[] = new int [5];

System.out.print(arr);

Tags:
Section:
Core Programming
Options:
Q11:

What is the output of this java program?

class array_output

{

public static void main(String args[])

{

int array_variable [] = new int[10];

for (int i = 0; i < 10; ++i)

{

array_variable[i] = i;

System.out.print(array_variable[i] + " ");

i++;

}

}

}

Tags:
Section:
Core Programming
Options:
Q12:

What is the output of this java program?

class multidimension_array

{

public static void main(String args[])

{

int arr[][] = new int[3][];

arr[0] = new int[1];

arr[1] = new int[2];

arr[2] = new int[3];               

int sum = 0;

for (int i = 0; i < 3; ++i)

for (int j = 0; j < i + 1; ++j)

arr[i][j] = j + 1;

for (int i = 0; i < 3; ++i)

for (int j = 0; j < i + 1; ++j)

sum  = sum +arr[i][j];

System.out.print(sum);               

}

}

Tags:
Section:
Core Programming
Options:
Q13:

What will be the output of below java program?

class array_output

{

public static void main(String args[])

{

int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};

int sum = 0;

for (int i = 0; i < 3; ++i)

for (int j = 0; j <  3 ; ++j)

sum = sum + array_variable[i][j];

System.out.print(sum / 5);

}

}

Tags:
Section:
Core Programming
Options:
Q14:

How to sort an array in java?

Tags:
Section:
Core Programming
Options:
Q15:

In java, which of these classes is not related to input and output stream in terms of functioning?

Tags:
Section:
Core Programming
Options:
Q16:

Which of these is a method for testing whether the specified element is a file or a directory in java?

Tags:
Section:
Core Programming
Options:
Q17:

What is the prototype of the default constructor of the class given below?

public class prototype { }

Tags:
Section:
Core Programming
Options:
Q18:

What will be the output of this java program?

import java.util.*;

public class NewTreeSet2 extends NewTreeSet

{

    public static void main(String [] args)

    {

        NewTreeSet2 t = new NewTreeSet2();

        t.count();

    }

}

protected class NewTreeSet

{

    void count()

    {

        for (int x = 0; x < 7; x++,x++ )

        {

            System.out.print(" " + x);

        }

    }

}

Tags:
Section:
Core Programming
Options:
Q19:

Which of these events will be generated if we close an applet’s window?

Tags:
Section:
Core Programming
Options:
Q20:

In java, which of these is a mechanism for naming and visibility control of a class and its content?

Tags:
Section:
Core Programming
Options: