Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 361 123456789101112131415 Java Questions 1 / 15 1. 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 2 / 15 2. 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 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. Find the output of the following code. class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x = 0; this.y = 0; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 2; double b = 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + " " + obj.y); } } A. 4 6.4 B. 6.4 6 C. 6.4 6.4 D. 6 6 5 / 15 5. What will be the output of the following Java program? class A { int i; public void display() { System.out.println(i); } } class B extends A { int j; public void display() { System.out.println(j); } } class Dynamic_dispatch { public static void main(String args[]) { B obj2 = new B(); obj2.i = 1; obj2.j = 2; A r; r = obj2; r.display(); } } A. 1 B. 2 C. 3 D. 4 6 / 15 6. Which of these method of Object class can clone an object? A. Objectcopy() B. copy() C. Object clone() D. clone() 7 / 15 7. 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 8 / 15 8. What will be the output of the following Java program? class recursion { int fact(int n) { int result; if (n == 1) return 1; result = fact(n - 1) * n; return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.fact(5)); } } A. 24 B. 30 C. 120 D. 720 9 / 15 9. 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 10 / 15 10. In Iterator, hasMoreElements() method of Enumeration has been changed to: A. hasNextElement() B. isNext() C. hasNext() D. name remains same 11 / 15 11. 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 12 / 15 12. Find the output of the following code. class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i; System.out.print(array_variable[i] + " "); i++; } } } A. 0 2 4 6 8 B. 1 3 5 7 9 C. 0 1 2 3 4 5 6 7 8 9 D. 1 2 3 4 5 6 7 8 9 10 13 / 15 13. 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 14 / 15 14. 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 15 / 15 15. Identify the output of the following program. String str = “Hellow”; System.out.println(str.indexOf(‘t)); A. 1 B. null C. -1 D. o Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By Wordpress Quiz plugin Quiz