JAVA MCQs with answers Page - 3

Dear candidates you will find MCQ questions of JAVA here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question

M

Manisha Agrawal • 9.34K Points
Tutor III

Q. Determine output:

Code:
class A{
        public static void main(String args[]){
	        int x;
 	        x = 10;
	        if(x == 10){
		        int y = 20;
		        System.out.print("x and y: "+ x + " " + y);
		        y = x*2;
	        }
	        y = 100;
	        System.out.print("x and y: " + x + " " + y);
        }
}
  • (A) 10 20 10 100
  • (B) 10 20 10 20
  • (C) 10 20 10 10
  • (D) Error

M

Manisha Agrawal • 9.34K Points
Tutor III

Q. Using which annotation non visible or private method can be tested?

  • (A) @NonVisible
  • (B) @Visible
  • (C) @VisibleForTesting
  • (D) @NonVisibleForTesting

M

Manisha Agrawal • 9.34K Points
Tutor III

Q. Automatic type conversion in Java takes place when

  • (A) Two type are compatible and size of destination type is shorter than source type.
  • (B) Two type are compatible and size of destination type is equal of source type.
  • (C) Two type are compatible and size of destination type is larger than source type.
  • (D) All of the above

M

Manisha Agrawal • 9.34K Points
Tutor III

Q. What is the output of the following program?

Code:
class A{
        public static void main(String args[]){
	        byte b;
   	        int i = 258;
	        double d = 325.59;

	        b = (byte) i;
	        System.out.print(b);

	        i = (int) d;
	        System.out.print(i);

                b = (byte) d;
                System.out.print(b);
        }
}
  • (A) 258 325 325
  • (B) 258 326 326
  • (C) 2 325 69
  • (D) Error

Login

Forgot username? click here

Forgot password? Click here

Don't have account? Register here.