MCQOPTIONS
Saved Bookmarks
This section includes 1671 Mcqs, each offering curated multiple-choice questions to sharpen your Technical Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1351. |
What is the output of this 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(6)); } } |
| A. | 1 |
| B. | 30 |
| C. | 120 |
| D. | 720 |
| Answer» E. | |
| 1352. |
What is the output of this 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(1)); } } |
| A. | 1 |
| B. | 30 |
| C. | 120 |
| D. | Runtime Error |
| Answer» B. 30 | |
| 1353. |
What is the output of this 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 |
| Answer» D. 720 | |
| 1354. |
What is the output of this program? class recursion { int func (int n) { int result; if (n == 1) return 1; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(5)); } } |
| A. | 0 |
| B. | 1 |
| C. | 120 |
| D. | None of the mentioned |
| Answer» C. 120 | |
| 1355. |
What is the output of this 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. | 0 |
| B. | 1 |
| C. | Compilation Error |
| D. | Runtime Error |
| Answer» E. | |
| 1356. |
Which of these packages contains the exception Stack Overflow in Java? |
| A. | java.lang |
| B. | java.util |
| C. | java.io |
| D. | java.system |
| Answer» B. java.util | |
| 1357. |
Which of these is not a correct statement? |
| A. | A recursive method must have a base case |
| B. | Recursion always uses stack |
| C. | Recursive methods are faster that programmers written loop to call the function repeatedly using a stack |
| D. | Recursion is managed by Java Runtime environment |
| Answer» E. | |
| 1358. |
Which of these will happen if recursive method does not have a base case? |
| A. | An infinite loop occurs |
| B. | System stops the program after some time |
| C. | After 1000000 calls it will be automatically stopped |
| D. | None of the mentioned |
| Answer» B. System stops the program after some time | |
| 1359. |
What is Recursion in Java? |
| A. | Recursion is a class |
| B. | Recursion is a process of defining a method that calls other methods repeatedly |
| C. | Recursion is a process of defining a method that calls itself repeatedly |
| D. | Recursion is a process of defining a method that calls other methods which in turn call again this method |
| Answer» C. Recursion is a process of defining a method that calls itself repeatedly | |
| 1360. |
What is the use of @syntax? |
| A. | Allows multiple parameters to be passed |
| B. | Allows one to put all your options into a file and pass this file as parameter |
| C. | Allows one to pass only one parameter |
| D. | Allows one to pass one file containing only one parameter |
| Answer» C. Allows one to pass only one parameter | |
| 1361. |
What is the output of below snippet run as $ java Demo –length 512 –breadth 2 -h 3 ? class Demo { @Parameter(names={"--length"}) int length; @Parameter(names={"--breadth"}) int breadth; @Parameter(names={"--height","-h"}) int height; public static void main(String args[]) { Demo demo = new Demo(); new JCommander(demo, args); demo.run(); } public void run() { System.out.println(length+" "+ breadth+" "+height); } } |
| A. | 2 512 3 |
| B. | 2 2 3 |
| C. | 512 2 3 |
| D. | 512 512 3 |
| Answer» D. 512 512 3 | |
| 1362. |
Which annotation is used to represent command line input and assigned to correct data type? |
| A. | @Input |
| B. | @Variable |
| C. | @Command Line |
| D. | @Parameter |
| Answer» E. | |
| 1363. |
Which class allows parsing of command line arguments? |
| A. | Args |
| B. | JCommander |
| C. | Command Line |
| D. | Input |
| Answer» C. Command Line | |
| 1364. |
How do we pass command line argument in Eclipse? |
| A. | Arguments tab |
| B. | Variable tab |
| C. | Cannot pass command line argument in eclipse |
| D. | Environment variable tab |
| Answer» B. Variable tab | |
| 1365. |
What would be the output of the following snippet, if compiled and executed with command line “hello there”? public class abc { String[] xyz; public static void main(String argv[]) { xyz=argv; } public void runMethod() { System.out.println(argv[1]); } } |
| A. | Compile time error |
| B. | Output would be “hello” |
| C. | Output would be “there” |
| D. | Output would be “hello there” |
| Answer» B. Output would be “hello” | |
| 1366. |
What is the output of the following snippet running with “java demo I write java code”? public class demo { public static void main(String args[]) { System.out.println(args[0]+""+args[args.length-1]); } } |
| A. | The snippet compiles, runs and prints “java demo” |
| B. | The snippet compiles, runs and prints “java code” |
| C. | The snippet compiles, runs and prints “demo code” |
| D. | The snippet compiles, runs and prints “I code” |
| Answer» E. | |
| 1367. |
What would be the output of following snippet, if compiled and executed with command line argument “java abc 1 2 3”? public class abc { static public void main(String [] xyz) { for(int n=1;n |
| A. | 1 2 |
| B. | 2 3 |
| C. | 1 2 3 |
| D. | Compilation error |
| Answer» C. 1 2 3 | |
| 1368. |
What would be the output of following snippet, if attempted to compile and execute? class abc { public static void main(String args[]) { if(args.length>0) System.out.println(args.length); } } |
| A. | The snippet compiles, runs and prints 0 |
| B. | The snippet compiles, runs and prints 1 |
| C. | The snippet does not compile |
| D. | The snippet compiles and runs but does not print anything |
| Answer» E. | |
| 1369. |
What would be the output of following snippet, if attempted to compile and run this code with command line argument “java abc Rakesh Sharma”? public class abc { int a=2000; public static void main(String argv[]) { System.out.println(argv[1]+" :-Please pay Rs."+a); } } |
| A. | Compile time error |
| B. | Compilation but runtime error |
| C. | Compilation and output Rakesh :-Please pay Rs.2000 |
| D. | Compilation and output Sharma :-Please pay Rs.2000 |
| Answer» B. Compilation but runtime error | |
| 1370. |
What is the output of this program, Command line execution is done as – “java Output command Line 10 A b 4 N”? class Output { public static void main(String args[]) { System.out.print("args[6]"); } } |
| A. | Java |
| B. | 10 |
| C. | b |
| D. | N |
| Answer» E. | |
| 1371. |
What is the output of this program, Command line execution is done as – “java Output command Line 10 A b 4 N”? class Output { public static void main(String args[]) { System.out.print("(int)args[2] * 2"); } } |
| A. | Java |
| B. | 10 |
| C. | 20 |
| D. | b |
| Answer» D. b | |
| 1372. |
What is the output of this program, Command line execution is done as – “java Output This is a command Line”? class Output { public static void main(String args[]) { System.out.print("args"); } } |
| A. | This |
| B. | java Output This is a command Line |
| C. | This is a command Line |
| D. | Compilation Error |
| Answer» D. Compilation Error | |
| 1373. |
What is the output of this program, Command line exceution is done as – “java Output This is a command Line”? class Output { public static void main(String args[]) { System.out.print("args[3]"); } } |
| A. | Java |
| B. | is |
| C. | This |
| D. | command |
| Answer» E. | |
| 1374. |
What is the output of this program, Command line execution is done as – “java Output This is a command Line”? class Output { public static void main(String args[]) { System.out.print("args[0]"); } } |
| A. | java |
| B. | output |
| C. | This |
| D. | is |
| Answer» D. is | |
| 1375. |
Can command line arguments be converted into int automatically if required? |
| A. | yes |
| B. | No |
| C. | Compiler Dependent |
| D. | Only ASCII characters can be converted |
| Answer» C. Compiler Dependent | |
| 1376. |
Which of these is a correct statement about args in this line of code? public static void main(String args[]) |
| A. | args is a String |
| B. | args is a Character |
| C. | args is an array of String |
| D. | args in an array of Character |
| Answer» D. args in an array of Character | |
| 1377. |
How many arguments can be passed to main()? |
| A. | Infinite |
| B. | Only 1 |
| C. | System Dependent |
| D. | None of the mentioned |
| Answer» B. Only 1 | |
| 1378. |
Which of these data types is used to store command line arguments? |
| A. | Array |
| B. | Stack |
| C. | String |
| D. | Integer |
| Answer» D. Integer | |
| 1379. |
Which of these method is given parameter via command line arguments? |
| A. | main() |
| B. | recursive() method |
| C. | Any method |
| D. | System defined methods |
| Answer» B. recursive() method | |
| 1380. |
What is the output of this program? class area { int width; int length; int height; area() { width = 5; length = 6; height = 1; } void volume() { volume = width * height * length; } } class cons_method { public static void main(String args[]) { area obj = new area(); obj.volume(); System.out.println(obj.volume); } } |
| A. | 0 |
| B. | 1 |
| C. | 25 |
| D. | 30 |
| Answer» E. | |
| 1381. |
What is the output of this program? class Output { static void main(String args[]) { int x , y = 1; x = 10; if(x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } |
| A. | 1 |
| B. | 2 |
| C. | Runtime Error |
| D. | Compilation Error |
| Answer» E. | |
| 1382. |
What is the output of this program? class box { int width; int height; int length; int volume; void volume() { volume = width * height * length; } void volume(int x) { volume = x; } } class Output { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(5); System.out.println(obj.volume); } } |
| A. | 0 |
| B. | 5 |
| C. | 25 |
| D. | 26 |
| Answer» C. 25 | |
| 1383. |
What is the output of this program? class equality { int x; int y; boolean isequal() { return(x == y); } } class Output { public static void main(String args[]) { equality obj = new equality(); obj.x = 5; obj.y = 5; System.out.println(obj.isequal); } } |
| A. | False |
| B. | True |
| C. | 0 |
| D. | 1 |
| Answer» C. 0 | |
| 1384. |
What is the output of this program? class box { int width; int height; int length; int volume; void volume(int height, int length, int width) { volume = width * height * length; } } class Prameterized_method{ public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(3, 2, 1); System.out.println(obj.volume); } } |
| A. | 0 |
| B. | 1 |
| C. | 6 |
| D. | 25 |
| Answer» D. 25 | |
| 1385. |
Which of these data type can be used for a method having a return statement in it? |
| A. | void |
| B. | int |
| C. | float |
| D. | both int and float |
| Answer» E. | |
| 1386. |
Which of these can be used to differentiate two or more methods having same name? |
| A. | Parameters data type |
| B. | Number of parameters |
| C. | Return type of method |
| D. | All of the mentioned |
| Answer» E. | |
| 1387. |
What is the process of defining more than one method in a class differentiated by parameters? |
| A. | Function overriding |
| B. | Function overloading |
| C. | Function doubling |
| D. | None of the mentioned |
| Answer» C. Function doubling | |
| 1388. |
Which of these is the method which is executed first before execution of any other thing takes place in a program? |
| A. | main method |
| B. | finalize method |
| C. | static method |
| D. | private method |
| Answer» D. private method | |
| 1389. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "hello"; String obj1 = "world"; String obj2 = "hello"; System.out.println(obj.equals(obj1) + " " + obj.equals(obj2)); } } |
| A. | false false |
| B. | true true |
| C. | true false |
| D. | false true |
| Answer» E. | |
| 1390. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "hello"; String obj1 = "world"; String obj2 = obj; obj2 = " world"; System.out.println(obj + " " + obj2); } } |
| A. | hello hello |
| B. | world world |
| C. | hello world |
| D. | world hello |
| Answer» D. world hello | |
| 1391. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.length()); } } |
| A. | 9 |
| B. | 10 |
| C. | 11 |
| D. | 12 |
| Answer» D. 12 | |
| 1392. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.charAt(3)); } } |
| A. | I |
| B. | L |
| C. | K |
| D. | E |
| Answer» B. L | |
| 1393. |
What is the output of this program? class string_demo { public static void main(String args[]) { String obj = "I" + "like" + "Java"; System.out.println(obj); } } |
| A. | I |
| B. | Like |
| C. | Java |
| D. | Like Java |
| Answer» E. | |
| 1394. |
Which of these method of String class can be used to test to strings for equality? |
| A. | isequal() |
| B. | isequals() |
| C. | equal() |
| D. | equals() |
| Answer» E. | |
| 1395. |
Which of these keywords is used to refer to member of base class from a subclass? |
| A. | upper |
| B. | Super |
| C. | this |
| D. | none of the mentioned |
| Answer» C. this | |
| 1396. |
Which of these method of String class is used to obtain character at specified index? |
| A. | char() |
| B. | Charat() |
| C. | charat() |
| D. | charAt() |
| Answer» E. | |
| 1397. |
String in Java is a? |
| A. | class |
| B. | object |
| C. | variable |
| D. | character array |
| Answer» B. object | |
| 1398. |
What is the output of this program? class Output { public static void main(String args[]) { int a1[] = new int[10]; int a2[] = {1, 2, 3, 4, 5}; System.out.println(a1.length + " " + a2.length); } } |
| A. | 10 5 |
| B. | 5 10 |
| C. | 0 10 |
| D. | 0 5 |
| Answer» B. 5 10 | |
| 1399. |
What is the output of this program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } |
| A. | 1 2 |
| B. | 1 2 3 |
| C. | 1 2 3 4 |
| D. | 1 2 3 4 5 |
| Answer» C. 1 2 3 4 | |
| 1400. |
What is the output of this program? class static_out { static int x; static int y; void add(int a , int b) { x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } } |
| A. | 7 7 |
| B. | 6 6 |
| C. | 7 9 |
| D. | 9 7 |
| Answer» D. 9 7 | |