Java Quiz October 6, 2024 | No Comments 0 votes, 0 avg 375 123456789101112131415 Java Questions 1 / 15 1. 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(); 2 / 15 2. 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 3 / 15 3. 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 4 / 15 4. Which variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed? A. Local variables B. Instance variables C. Class Variables D. Static variables 5 / 15 5. 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 6 / 15 6. Which of these keywords is used to prevent content of a variable from being modified? A. final B. last C. constant D. static 7 / 15 7. In Iterator, hasMoreElements() method of Enumeration has been changed to: A. hasNextElement() B. isNext() C. hasNext() D. name remains same 8 / 15 8. How to format date from one form to another? A. SimpleDateFormat B. DateFormat C. SimpleFormat D. DateConverter 9 / 15 9. What will be the output of the following Java program? class Output { public static void main(String args[]) { double x = 2.0; double y = 3.0; double z = Math.pow( x, y ); System.out.print(z); } } A. 9.O B. 8.O C. 4.O D. 2.O 10 / 15 10. 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 11 / 15 11. 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 12 / 15 12. What is an assignment statement? A. Adding a number to an int B. Assigning a multiplication C. Assigning a name to a variable D. Assigning a value to a variable 13 / 15 13. 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 14 / 15 14. File class is included in which package? A. java.io package B. java.util.package C. java.lang package D. java.net.package 15 / 15 15. 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 Your score isThe average score is 36% LinkedIn Facebook VKontakte 0% Restart quiz By Wordpress Quiz plugin Quiz