MCQOPTIONS
Saved Bookmarks
This section includes 34 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. |
In the below code, which call to num() method is appropriate?class Result { public static int num(int ...x) { return; } static void main(String args[]) { num(10); num(10,20); num(10,20,30); num(10,20,30,40); } } |
| A. | only num(10,20) |
| B. | only num(10) |
| C. | only num(10) & num(10,20) |
| D. | all of the mentioned |
| E. | None of these |
| Answer» E. None of these | |
| 2. |
What is the output of this program?class box_Shape { int width; int height; int length; int vol; void vol() { vol = height * width * length; } } public class Result { public static void main(String args[]) { box_Shape obj = new box_Shape(); obj.height = 5; obj.length = 10; obj.width = 3; obj.vol(); System.out.println(obj.vol); } } |
| A. | 150 |
| B. | 100 |
| C. | 200 |
| D. | 50 |
| E. | 250 |
| Answer» B. 100 | |
| 3. |
What is the output of this program?class equal { int p; int q; boolean isequal() { return(p == q); } } public class Result { public static void main(String args[]) { equal obj = new equal(); obj.p = 7; obj.q = 10; System.out.println(obj.isequal()); } } |
| A. | Compiletime error |
| B. | false |
| C. | Runtime error |
| D. | true |
| E. | None of these |
| Answer» C. Runtime error | |
| 4. |
What is the output of this program?class box_Shape { int width; int height; int length; int volume; void volume(int heigth, int lenght, int width) { volume = width*height*length; } } public class Prameterized_method_Example { public static void main(String args[]) { box_Shape obj = new box_Shape(); obj.height = 5; obj.length = 6; obj.width = 10; obj.volume(5,6,10); System.out.println(obj.volume); } } |
| A. | 100 |
| B. | 200 |
| C. | 300 |
| D. | 400 |
| E. | 500 |
| Answer» D. 400 | |
| 5. |
What is the output of this program?class calcluation { int p; int q; void calc(int K , int L) { K *= 5; L /= 5; } } public class result { public static void main(String args[]) { calculation obj = new calculation(); int p = 20; int q = 40; obj.calc(p , q); System.out.println(p + " " + q); } } |
| A. | 10 20 |
| B. | 20 40 |
| C. | 30 40 |
| D. | 40 20 |
| E. | 20 10 |
| Answer» C. 30 40 | |
| 6. |
What is the output of this program?class method { int p; double q; void add(int n1 , int n2) { p = n1 + n2; } void add(double n3 , double n4) { q = n3 + n4; } method() { this.p = 0; this.q = 0; } } public class method_overload { public static void main(String args[]) { method obj = new method(); int n1 = 5; double n2 = 7.5; obj.add(n1, n1); obj.add(n2, n2); System.out.println(obj.p + " " + obj.q); } } |
| A. | 10 15.0 |
| B. | 10.0 15 |
| C. | 15 10 |
| D. | 10.0 15.0 |
| E. | None of these |
| Answer» B. 10.0 15 | |
| 7. |
What is the output of this program?class method { int p; int q; void add(int n1) { p = n1 + 3; } void add(int n1 , int n2) { p = n1 + 5; } } public class Method_overloading { public static void main(String args[]) { method obj = new method(); int n1 = 0; obj.add(10, 20); System.out.println(obj.p); } } |
| A. | 11 |
| B. | 12 |
| C. | 13 |
| D. | 14 |
| E. | 15 |
| Answer» F. | |
| 8. |
What is the output of this program?class method { int p; int q; void add(int n) { p = n + 2; } void add(int n, int b) { p = n + 5; } } public class method_overloading { public static void main(String args[]) { method obj = new method(); int n = 0; obj.add(10); System.out.println(obj.p); } } |
| A. | 10 |
| B. | 11 |
| C. | 12 |
| D. | 13 |
| E. | 14 |
| Answer» C. 12 | |
| 9. |
What is the output of the following code?public class output{ public void method1 (int i,float f) { System.out.println(" int float method"); } public void method2(float f,int i); { System.out.println("float int method"); } public static void main(String[]args) { output s=new output(); s.method1(10,10); }} |
| A. | float int method |
| B. | int float method |
| C. | Runtime error |
| D. | Compiletime error |
| E. | None of these |
| Answer» E. None of these | |
| 10. |
What is the output of this program?class calclution { int p; int q; calclution(int K, int L) { p = K; q = L; } void calc(calclution n) { n.p *= 2; n.p /= 2; } } public class Result { public static void main(String args[]) { calclution obj = new calclution(50 , 20); obj.calc(obj); System.out.println(obj.p + " " + obj.q); } } |
| A. | 20 30 |
| B. | 50 20 |
| C. | 40 10 |
| D. | 20 50 |
| E. | 10 10 |
| Answer» C. 40 10 | |
| 11. |
What is the output of this program?class box_Shape { int w; int h; int l; int vol; void vol() { vol = w * h * l; } void vol(int p) { vol = p; } } public class Result { public static void main(String args[]) { box_Shape bs = new box_Shape(); bs.h = 2; bs.l = 7; bs.w = 6; bs.vol(6); System.out.println(bs.vol); } } |
| A. | 50 |
| B. | 5 |
| C. | 60 |
| D. | 6 |
| E. | 16 |
| Answer» E. 16 | |
| 12. |
What is the output of this program?public class Result { public static void main(String args[]) { long start, end; start = System.currentTimeMillis(); for (int k = 0; k < 10000000; k++); end = System.currentTimeMillis(); System.out.print(end - start); } } |
| A. | 0 |
| B. | 1 |
| C. | 200 |
| D. | 30 |
| E. | System Dependent |
| Answer» F. | |
| 13. |
What is the output of this program?public class Result { public static void main(String args[]) { Long n = new Long(230); System.out.print(n.hashCode()); } } |
| A. | 220 |
| B. | 220.0 |
| C. | 230 |
| D. | 230.0 |
| E. | 250 |
| Answer» D. 230.0 | |
| 14. |
What is the output of this program?public class Result { public static void main(String args[]) { double num0 = 4.15; double num1 = 5.16; double num2 = Math.max( num0, num1 ); System.out.print(num2); } } |
| A. | 5 |
| B. | 5.1 |
| C. | 4.15 |
| D. | 4.1 |
| E. | 5.16 |
| Answer» F. | |
| 15. |
What is the output of this program?public class Math_Example { public static void main(String args[]) { int num0 = 10; int num1 = (int) Math.abs(num0); System.out.print(num1); } } |
| A. | 10.0 |
| B. | 10 |
| C. | 1 |
| D. | 0 |
| E. | None of these |
| Answer» C. 1 | |
| 16. |
What is the output of this program?public class Result { public static void main(String args[]) { byte array0[] = { 71, 72, 73, 74, 75, 76 }; byte array1[] = { 77, 78, 79, 80, 81, 82 }; System.arraycopy(array0 , 1, array1, 3, 0); System.out.print(new String(array0) + " " + new String(array1)); } } |
| A. | GHIJKL |
| B. | MNOPQR |
| C. | GHIJKL MNOPQR |
| D. | GHIJKLMNOPQR |
| E. | None of these |
| Answer» D. GHIJKLMNOPQR | |
| 17. |
What is the output of this program?public class Result { public static void main(String args[]) { byte array0[] = { 71, 72, 73, 74, 75, 76 }; byte array1[] = { 77, 78, 79, 80, 81, 82 }; System.arraycopy(array0 , 2, array1, 1, array0.length-2); System.out.print(new String(array0) + " " + new String(array1)); } } |
| A. | GHIJKL |
| B. | MIJKLR |
| C. | GHIJKLMIJKLR |
| D. | GHIJKL MIJKLR |
| E. | None of these |
| Answer» E. None of these | |
| 18. |
What is the output of this program?public class Result { public static void main(String args[]) { byte array0[] = { 71, 72, 73, 74, 75, 76 }; byte array1[] = { 77, 78, 79, 80, 81, 82 }; System.arraycopy(array0 , 0, array1, 0, array0.length); System.out.print(new String(array0) + " " + new String(array1)); } } |
| A. | GHIJKL |
| B. | GHIJKL GHIJKL |
| C. | GHIJKLGHIJKL |
| D. | GHIJKL GHIJ |
| E. | None of these |
| Answer» C. GHIJKLGHIJKL | |
| 19. |
What is the output of this program?public class Output { public static void main(String args[]) { double num0 = 5.0; double num1 = 2.0; double num2 = Math.pow( num0, num1 ); System.out.print(num2); } } |
| A. | 5 |
| B. | 2 |
| C. | 25 |
| D. | 25.0 |
| E. | 52 |
| Answer» E. 52 | |
| 20. |
What is the output of this program?public class Result { public static void main(String args[]) { Double num0 = new Double(260.0062); Double num1 = new Double(260.0062123456); try { int p = num1.compareTo(num0); System.out.print(p); } catch(ClassCastException e) { System.out.print("Exception"); } } } |
| A. | Exception |
| B. | 0 |
| C. | 1 |
| D. | -1 |
| E. | None of these |
| Answer» D. -1 | |
| 21. |
What is the output of this program?public class Result { public static void main(String args[]) { Double num = new Double(260.00625023); float p = num.floatValue(); System.out.print(p); } } |
| A. | 260.00626 |
| B. | 260 |
| C. | 260.00625023 |
| D. | 260.00 |
| E. | 260.260 |
| Answer» B. 260 | |
| 22. |
What is the output of this program?public class Result { public static void main(String args[]) { Double num = new Double(260.062); int p = num.intValue(); System.out.print(p); } } |
| A. | 260.062 |
| B. | 260 |
| C. | 260.06 |
| D. | 260.0 |
| E. | 260.260 |
| Answer» C. 260.06 | |
| 23. |
What is the output of this program?public class Result { public static void main(String args[]) { Double num = new Double(260.1); boolean p = num.isNaN(); System.out.print(p); } } |
| A. | 260.1 |
| B. | 260 |
| C. | true |
| D. | false |
| E. | None of these |
| Answer» E. None of these | |
| 24. |
What is the output of this program?public class Result { public static void main(String args[]) { Integer n = new Integer(260); float p = n.floatValue(); System.out.print(p); } } |
| A. | 250 |
| B. | 250.0 |
| C. | 260 |
| D. | 260.0 |
| E. | None of these |
| Answer» E. None of these | |
| 25. |
What is the output of this program?class equal { int p; int q; boolean isequal() { return(p == q); } } public class Result { public static void main(String args[]) { equal equ = new equal(); equ.p = 7; equ.q = 5; System.out.println(equ.isequal()); } } |
| A. | false |
| B. | true |
| C. | true false |
| D. | false true |
| E. | None of these |
| Answer» B. true | |
| 26. |
What is the output of this program?class box_Shape { int w; int h; int l; int vol; void vol(int h, int l, int w) { vol = w * h * l; } } public class Prameterized_method_Example { public static void main(String args[]) { box_Shape obj = new box_Shape(); obj.h = 6; obj.l = 3; obj.w = 4; obj.vol(6, 3, 4); System.out.println(obj.vol); } } |
| A. | 68 |
| B. | 70 |
| C. | 72 |
| D. | 74 |
| E. | 76 |
| Answer» D. 74 | |
| 27. |
What is the output of this program?class box_Shape { int width; int length; int height; int volume; box_Shape() { width=8; length=3; height=5; } void volume() { volume = width*length*height; } } public class cons_method_Example { public static void main(String args[]) { box_Shape obj = new box_Shape(); obj.volume(); System.out.println(obj.volume); } } |
| A. | 100 |
| B. | 110 |
| C. | 120 |
| D. | 130 |
| E. | 140 |
| Answer» D. 130 | |
| 28. |
What is the output of this program?public class Result { public static void main(String args[]) { double num0 = 205; double num1 = 2; double num2 = Math.IEEEremainder(num0, num1); System.out.print(num2); } } |
| A. | 250 |
| B. | 2 |
| C. | 11 |
| D. | 1.0 |
| E. | None of these |
| Answer» E. None of these | |
| 29. |
What is the output of this program?public class Result { public static void main(String args[]) { double num =3.14; int p = (int) Math.toRadians(num); System.out.print(p); } } |
| A. | 0 |
| B. | 1 |
| C. | 3.14 |
| D. | 3 |
| E. | None of these |
| Answer» B. 1 | |
| 30. |
What is the output of this program?public class Result { public static void main(String args[]) { double num = 4.13; int p = (int) Math.toDegrees(num); System.out.print(p); } } |
| A. | 236 |
| B. | 4.13 |
| C. | 230 |
| D. | 200 |
| E. | None of these |
| Answer» B. 4.13 | |
| 31. |
Which of these method returns a smallest whole number greater than or equal to variable p? |
| A. | double floor(double p) |
| B. | double max(double p) |
| C. | double min(double p) |
| D. | double ciel(double p) |
| E. | None of these |
| Answer» E. None of these | |
| 32. |
In the below code, which call to num() method is appropriate? |
| A. | only num(10,20) |
| B. | only num(10) |
| C. | only num(10) & num(10,20) |
| D. | all of the mentioned |
| E. | None of these |
| Answer» E. None of these | |
| 33. |
At line number 2 below, choose 3 valid data-type attributes/qualifiers among final, static, native, public, private, abstract, protected |
| A. | final, static, protected |
| B. | static, final, public |
| C. | abstract, final, private |
| D. | native, final, private |
| E. | None of these |
| Answer» C. abstract, final, private | |
| 34. |
Which of the following is a method having same name as that of it s class? |
| A. | delete |
| B. | constructor |
| C. | finalize |
| D. | class |
| E. | None of these |
| Answer» C. finalize | |