Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 279 123456789101112131415 Java Questions 1 / 15 1. Which of these statements are incorrect? A. The left shift operator, <<, shifts all of the bits in a value to the left specified number of times B. The right shift operator, >>, shifts all of the bits in a value to the right specified number of times C. The left shift operator can be used as an alternative to multiplying by 2 D. The right shift operator automatically fills the higher order bits with 0 2 / 15 2. What will be the output of the following Java code? class Char { public static void main(String args[]) { char ch1, ch2; ch1 = 88; // code for X ch2 = 'Y'; System.out.print("ch1 and ch2: "); System.out.println(ch1 + " " + ch2); } } A. ch1 and ch2: X Y B. ch1 and ch2: x y C. ch1 and ch2: 1 3 D. None of the above 3 / 15 3. Which two classes use the Shape class correctly? A. public class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public abstract class Circle implements Shape { private int radius; public void draw(); } E. public class Circle extends Shape { private int radius; public void draw() { /* code here */ } } F. public abstract class Circle implements Shape { private int radius; public void draw() { /* code here */ } } A. B,E B. A,C C. C,E D. T,H 4 / 15 4. 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 5 / 15 5. What will be the output of the following Java code? class San { public void m1 (int i,float f) { System.out.println(" int float method"); } public void m1(float f,int i); { System.out.println("float int method"); } public static void main(String[]args) { San s=new San(); s.m1(20,20); } } A. int float method B. float int method C. compile time error D. run time error 6 / 15 6. Which of these can be used to differentiate two or more methods having the same name? A. Parameters data type B. Number of parameters C. Return type of method D. All of the mentioned 7 / 15 7. Which of these statements is incorrect about Thread? A. start() method is used to begin execution of the thread B. run() method is used to begin execution of a thread before start() method in special cases C. A thread can be formed by implementing Runnable interface only D. A thread can be formed by a class that extends Thread class 8 / 15 8. What will be the output of the following Java code? class A { public int i; protected int j; } class B extends A { int j; void display() { super.j = 3; System.out.println(i + " " + j); } } class Output { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } A. 1 2 B. 2 1 C. 1 3 D. 3 1 9 / 15 9. What will be the output of the following Java code? class static_out { static int x; static int y; void add(int a, int b) { x = a + b; y = x + b; } } public class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } } A. 7 7.4 B. 6 6.4 C. 7 9 D. 9 7 10 / 15 10. What is an ineterface? A. An interface is a collection of abstract methods B. Interface is an abstract class C. Interface is a concrete class D. none of the above 11 / 15 11. Identify the modifier which cannot be used for constructor. A. public B. protected C. private D. static 12 / 15 12. 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 13 / 15 13. 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 14 / 15 14. 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 15 / 15 15. What will be the output of the following Java code? class output { public static void main(String args[]) { String chars[] = {"a", "b", "c", "a", "c"}; for (int i = 0; i < chars.length; ++i) for (int j = i + 1; j < chars.length; ++j) if(chars[i].compareTo(chars[j]) == 0) System.out.print(chars[j]); } } A. ab B. bc C. ca D. ac Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By Wordpress Quiz plugin Quiz