Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 371 123456789101112131415 Java Questions 1 / 15 1. Find the output of the following code. import java.util.*; class Collection_iterators { public static void main(String args[]) { LinkedList list = new LinkedList(); list.add(new Integer(2)); list.add(new Integer(8)); list.add(new Integer(5)); list.add(new Integer(1)); Iterator i = list.iterator(); Collections.reverse(list); Collections.sort(list); while(i.hasNext()) System.out.print(i.next() + " "); } } A. 1 2 5 8 B. 2 1 8 5 C. 1 5 8 2 D. 2 8 5 1 2 / 15 2. What is not the use of “this” keyword in Java? A. Referring to the instance variable when a local variable has the same name B. Passing itself to the method of the same class C. Passing itself to another method D. Calling another constructor in constructor chaining 3 / 15 3. How to convert Date object to String? A. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date()); B. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date()); C. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().parse(); D. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().format(); 4 / 15 4. Identify the modifier which cannot be used for constructor. A. public B. protected C. private D. static 5 / 15 5. The following program is an example for? class Student{ int id; String name; void display(){System.out.println(id+" "+name);} public static void main(String args[]){ Student s1=new Student(); Student s2=new Student(); s1.display(); s2.display(); } } A. Parameterized constructor B. Default Constructor C. Overloading Constructor D. None of the above 6 / 15 6. Which of these keywords are used for the block to be examined for exceptions? A. check B. throw C. catch D. try 7 / 15 7. What will be the output of the following Java program? class recursion { int func (int n) { int result; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(12)); } } A. O B. 1 C. Compilation error D. run time error 8 / 15 8. Which of the following is a superclass of every class in Java? A. ArrayList B. Abstract class C. Object class D. String 9 / 15 9. Find the output of the following code. import java.util.Scanner; class ThisKeyword { private int a = 4; private int b = 1; void getSum(int a, int b) { this.a = a; this.b = b; System.out.println(this.a + this.b); } } public class Main { public static void main(String args[]) { ThisKeyword T = new ThisKeyword(); T.getSum(3, 5); } } A. 5 B. 9 C. 8 D. 4 10 / 15 10. Which of the following is true in regard to applet execution? A. Applets loaded and executing locally have some restrictions faced by applets that get loaded from the network. B. Applets loaded and executing locally have none of the restrictions faced by applets that get loaded from the network. C. Applets loaded from the same computer where they are executing have the same restrictions as applets loaded from the network. D. Applets cant react to user input and change dynamically 11 / 15 11. What is not the use of “this” keyword in Java? A. Referring to the instance variable when a local variable has the same name B. Passing itself to the method of the same class C. Passing itself to another method D. Calling another constructor in constructor chaining 12 / 15 12. What is the default value of String variable? A. “” B. '’ C. null D. not defined 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. 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 15 / 15 15. Find the output of the following code. 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); } } A. 0 256 B. 0 64 C. 256 0 D. 64 0 Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By Wordpress Quiz plugin Quiz