Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 44 123456789101112131415 Java Questions 1 / 15 1. 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 2 / 15 2. 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 3 / 15 3. 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 4 / 15 4. Which of these is correct about passing an argument by call-by-value process? A. Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument B. Copy of argument is made into the formal parameter of the subroutine C. Reference to original argument is passed to formal parameter of the subroutine D. Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument 5 / 15 5. What will be the output of the following Java code snippet? class abc { public static void main(String args[]) { if(args.length>0) System.out.println(args.length); } } A. The snippet compiles and runs but does not print anything B. The snippet compiles, runs and prints 0 C. The snippet compiles, runs and prints 1 D. The snippet does not compile 6 / 15 6. 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. 7 / 15 7. Which of the following is not an OOPS concept in Java? A. Polymorphism B. Inheritance C. Compilation D. Encapsulation 8 / 15 8. Which of these keywords are used for the block to be examined for exceptions? A. check B. throw C. catch D. try 9 / 15 9. What is true about final class? A. class declared final is a final class B. final classes are created so the methods implemented by that class cannot be overidden C. It can’t be inherited D. all of the above 10 / 15 10. Which of these is an incorrect array declaration? A. int arr[] = new int[5] B. int [] arr = new int[5] C. int arr[] = new int[5] D. int arr[] = int [5] new 11 / 15 11. 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 12 / 15 12. How to format date from one form to another? A. SimpleDateFormat B. DateFormat C. SimpleFormat D. DateConverter 13 / 15 13. Which environment variable is used to set the java path? A. MAVEN_Path B. JavaPATH C. JAVA D. JAVA_HOME 14 / 15 14. Find the output of the following code. class bool_operator { public static void main(String args[]) { boolean a = true; boolean b = !true; boolean c = a | b; boolean d = a & b; boolean e = d ? b : c; System.out.println(d + " " + e); } } A. true false B. false false C. true true D. false true 15 / 15 15. Which of these jump statements can skip processing the remainder of the code in its body for a particular iteration? A. break B. return C. exit D. continue Your score is The average score is 30% LinkedIn Facebook Twitter VKontakte 0% Restart quiz Quiz