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
πŸ’¬ Discuss
βœ… Correct Answer: (D) Error

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

  • (A) @NonVisible
  • (B) @Visible
  • (C) @VisibleForTesting
  • (D) @NonVisibleForTesting
πŸ’¬ Discuss
βœ… Correct Answer: (C) @VisibleForTesting
Explanation:

@VisibleForTesting is an annotation provided by Google's Guava library.

  • It is used to mark methods, fields, or classes that are more visible than otherwise necessary just to make them accessible for testing.
  • This annotation acts as documentation to indicate that something which is public or protected should not be used in production code, but is made accessible only for unit tests.

Example usage:

@VisibleForTesting
void someInternalMethod() {
// implementation
}

This helps maintain encapsulation while still allowing thorough testing.

Note: This annotation does not magically make private methods accessible to tests; you must change their visibility to package-private or protected and annotate them to indicate the reason.

Q. Which one of the following is not an annotation used by Junit with Junit4?

  • (A) @Ignored
  • (B) @AfterClass
  • (C) @BeforeClass
  • (D) @Test
πŸ’¬ Discuss
βœ… Correct Answer: (A) @Ignored

Q. Which one of the following is not ID generating strategy using @GeneratedValue annotation?

  • (A) Sequence
  • (B) Identity
  • (C) Manual
  • (D) Auto
πŸ’¬ Discuss
βœ… Correct Answer: (C) Manual

Q. Which one of the following annotations is not used in Hibernate?

  • (A) @Basic
  • (B) @Entity
  • (C) @Query
  • (D) @Column
πŸ’¬ Discuss
βœ… Correct Answer: (C) @Query

Q. Annotations which are applied to other annotations are called meta annotations.

  • (A) False
  • (B) True
  • (C) ---
  • (D) ---
πŸ’¬ Discuss
βœ… Correct Answer: (B) True

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
πŸ’¬ Discuss
βœ… Correct Answer: (C) Two type are compatible and size of destination type is larger than source type.

Q. Which of the following automatic type conversion will be possible?

  • (A) short to int
  • (B) byte to int
  • (C) int to long
  • (D) long to int
πŸ’¬ Discuss
βœ… Correct Answer: (C) int to long

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
πŸ’¬ Discuss
βœ… Correct Answer: (C) 2 325 69

Q. Which of the following is not pre defined annotation in Java?

  • (A) @FunctionInterface
  • (B) @SafeVarags
  • (C) @Overriden
  • (D) @Deprecated
πŸ’¬ Discuss
βœ… Correct Answer: (C) @Overriden