Java Questions March 14, 2023 | No Comments 0 votes, 0 avg 1 123456789101112131415 Java Questions 1 / 15 1. Which concept of Java is achieved by combining methods and attribute into a class? A. Encapsulation B. Inheritance C. Polymorphism D. Abstraction 2 / 15 2. What will be the output of the following Java program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } A. 1 2 3 4 5 B. 1 2 3 4 C. 1 2 D. 1 2 3 3 / 15 3. What is the syntax for java main method? A. public void main(String[] args) B. public static void main() C. public static void main(String[] args) D. none of the above 4 / 15 4. Identify the modifier which cannot be used for constructor. A. public B. protected C. private D. static 5 / 15 5. What will be the output of the following Java code? class output { public static void main(String args[]) { String a = "hello i love java"; System.out.println(a.indexOf('i')+" "+a.indexOf('o') +" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o')); } } A. 6 4 6 9 B. 5 4 5 9 C. 7 8 8 9 D. 4 3 6 9 6 / 15 6. Which mechanism is used when a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed? A. Inter-thread communication B. Initial-thread communication C. Mutual Exclusive D. none of the above 7 / 15 7. What will be the output of the following Java program? class recursion { int func (int n) { int result; if (n == 1) return 1; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(5)); } } A. 1 B. 120 C. O D. None of the mentioned 8 / 15 8. What is the process of defining a method in terms of itself, that is a method that calls itself? A. Polymorphism B. Abstraction C. Encapsulation D. Recursion 9 / 15 9. What will be the output of the following Java program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } A. 1 2 B. 1 2 3 C. 1 2 3 4 D. 1 2 3 4 5 10 / 15 10. Which of the following is not an OOPS concept in Java? A. Polymorphism B. Inheritance C. Compilation D. Encapsulation 11 / 15 11. How is Date stored in database? A. java.sql.Date B. java.util.Date C. java.sql.DateTime D. java.util.DateTime 12 / 15 12. What is the function of javap command? A. This command is used to run java compiler B. A command to run a non-optimized version of the java compiler C. A command to create HTML document in API style D. A command to seperate java class files 13 / 15 13. A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction? A. Declare the method with the keyword protected B. Declare the method with the keyword private C. Do not declare the method with any accessibility modifiers D. Declare the method with the keyword public and private. 14 / 15 14. Find the output of the following program. public class Solution{ public static void main(String[] args){ byte x = 127; x++; x++; System.out.print(x); } } A. -127 B. 2 C. 129 D. 127 15 / 15 15. Find the value of A[1] after execution of the following program. int[] A = {0,2,4,1,3}; for(int i = 0; i < a.length; i++){ a[i] = a[(a[i] + 3) % a.length]; } A. 1 B. 2 C. 3 D. o Your score is The average score is 27% LinkedIn Facebook Twitter VKontakte 0% Restart quiz Questions, Quiz