

MCQOPTIONS
Saved Bookmarks
This section includes 21 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
1. |
What is the output of this program?
class Average { public static void main(String args[]) { double number[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double res; res = 0; for (int i = 0; i < 6; ++i) { res = res + number[i]; } System.out.print(res/6); } } |
A. | 16.34 |
B. | 16.566666644 |
C. | 16.46666666666667 |
D. | 16.46666666666666 |
E. | NA |
Answer» D. 16.46666666666666 | |
2. |
What is the output of this program?
|
A. | 36 |
B. | 25 |
C. | 30 |
D. | 40 |
E. | 12 |
Answer» B. 25 | |
3. |
What is the output of this program?
class area { public static void main(String args[]) { double r, pi, a; r = 6.8; pi = 3.14; a = pi * r * r; System.out.println(a); } } |
A. | 142.1935 |
B. | 145.1936 |
C. | 140.236 |
D. | 145.2936 |
E. | 145 |
Answer» C. 140.236 | |
4. |
What will be the output of these statement?
class output { public static void main(String args[]) { double p, q, r; p = 3.0/0; q = 0/4.0; r = 0/0.0; System.out.println(p); System.out.println(q); System.out.println(r); } } |
A. | 0.0 |
B. | Infinity |
C. | NaN |
D. | all of the mentioned |
E. | None of these |
Answer» E. None of these | |
5. |
What is the output of this program?
class output { public static void main(String args[]) { boolean var11 = true; boolean var12 = false; if (var12) { System.out.println(var12); } else { System.out.println(var11); } } } |
A. | 0 |
B. | false |
C. | true |
D. | 1 |
E. | None of these |
Answer» C. true | |
6. |
What is the output of this program?
class output { public static void main(String args[]) { char a = 'A'; a++; System.out.print((int)a); } } |
A. | 61 |
B. | 64 |
C. | 65 |
D. | 63 |
E. | 66 |
Answer» F. | |
7. |
What is the output of this program?
class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'j'; System.out.print(array_variable[i] + "" ); i++; } } } |
A. | i i i i i |
B. | 0 1 2 3 4 |
C. | i j k l m |
D. | j j j j j |
E. | None of the mentioned |
Answer» E. None of the mentioned | |
8. |
What is the output of this program?
class output { public static void main(String args[]) { char var11 = 'A'; char var12 = 'a'; System.out.println((int)var11 + " " + (int)var12); } } |
A. | 162 |
B. | 67 95 |
C. | 65 97 |
D. | 66 98 |
E. | None of these |
Answer» D. 66 98 | |
9. |
What is the output of this program?
class booloperators { public static void main(String args[]) { boolean var11 = true; boolean var12 = false; System.out.println((var11 & var12)); } } |
A. | 0 |
B. | true |
C. | false |
D. | 1 |
E. | None of these |
Answer» D. 1 | |
10. |
What is the output of below code snippet?
enum Enums { D, E, F; private Enums() { System.out.println(20); } } public class MainClass { public static void main(String[] args) { Enum en = Enums.E; } } |
A. | Runtime Exception |
B. | 20 |
C. | Compilation Error |
D. | 10 |
E. | None of these |
Answer» C. Compilation Error | |
11. |
What is the output of below code snippet?
enum Levels { private BOTTOM, public MEDIUM, protected TOP; } |
A. | Runtime Error |
B. | EnumNotDefined Exception |
C. | Compilation Error |
D. | It runs successfully |
E. | None of these |
Answer» D. It runs successfully | |
12. |
What is the output of below code snippet?
class Z { } enum Enums extends Z { DCB, FEG, HIJ, LMN; } |
A. | Compilation Error |
B. | Runtime Error |
C. | It runs successfully |
D. | EnumNotDefined Exception |
E. | None of these |
Answer» B. Runtime Error | |
13. |
What will ordinal() method provide?
enum Season { WINTER, SPRING, SUMMER, FALL }; System.out.println(Season.WINTER.ordinal()); |
A. | 1 |
B. | 0 |
C. | 3 |
D. | 2 |
E. | -1 |
Answer» C. 3 | |
14. |
Which of the following are legal lines of Java code?
|
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | All statements are correct. |
E. | NA |
Answer» E. NA | |
15. |
Which of the below data type doesn t support overloaded methods for +,-,* and /? |
A. | BigDecimal |
B. | double |
C. | float |
D. | int |
E. | None of these |
Answer» B. double | |
16. |
What will ordinal() method provide? |
A. | 1 |
B. | 0 |
C. | 3 |
D. | 2 |
E. | -1 |
Answer» C. 3 | |
17. |
What is the replacement of joda time library in java 8? |
A. | java.joda |
B. | java.date (JSR-310) |
C. | java.jodaTime |
D. | java.time (JSR-310) |
E. | None of these |
Answer» E. None of these | |
18. |
How to get difference between two dates? |
A. | Time diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); |
B. | Date diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); |
C. | long diffInMilli = java.time.Duration.between(dateTime1, dateTime2).toMillis(); |
D. | long diffInMilli = java.time.difference(dateTime1, dateTime2).toMillis(); |
E. | None of these |
Answer» D. long diffInMilli = java.time.difference(dateTime1, dateTime2).toMillis(); | |
19. |
How is Date stored in database? |
A. | java.util.Date |
B. | java.sql.Date |
C. | java.sql.DateTime |
D. | java.util.DateTime |
E. | None of these |
Answer» C. java.sql.DateTime | |
20. |
What will be the output of these statement? |
A. | 0.0 |
B. | Infinity |
C. | NaN |
D. | all of the mentioned |
E. | None of these |
Answer» E. None of these | |
21. |
Which of the following are legal lines of Java code? |
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | All statements are correct. |
E. | NA |
Answer» E. NA | |