

MCQOPTIONS
Saved Bookmarks
This section includes 56 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. |
Java does not allow nesting of methods. (TRUE / FALSE) |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
2. |
What is the output of the below Java program with a final local variable? |
A. | 30 |
B. | 20 |
C. | 10 |
D. | Compiler error |
Answer» E. | |
3. |
What is the output of the Java program with static variables? |
A. | t6 BIRDS before=25 |
B. | t6 BIRDS before=25 |
C. | t6 BIRDS before=25 |
D. | None |
Answer» C. t6 BIRDS before=25 | |
4. |
A static-method or a static-variable is shared among all instances of a class. (TRUE / FALSE) |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
5. |
In Java, local variables are stored in __ memory and instance variables are stored in ___ memory. |
A. | Stack, Stack |
B. | Heap, Heap |
C. | Stack, Heap |
D. | Heap, Stack |
Answer» D. Heap, Stack | |
6. |
A local variable declared inside a method can not be used in expressions without initializing it first. (TRUE / FALSE). |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
7. |
What is the output of the below Java program with a "this" operator? |
A. | CAKES=5 |
B. | CAKES=0 |
C. | CAKES=10 |
D. | Compiler error |
Answer» D. Compiler error | |
8. |
A "this" operator used inside a Java method refers to ___ variable. |
A. | Global variable |
B. | Method local variable |
C. | Instance variable |
D. | None |
Answer» D. None | |
9. |
What is the output of the below Java program with a void method? |
A. | SHOW Method 2 |
B. | No output |
C. | Compiler error |
D. | None |
Answer» B. No output | |
10. |
What is the output of the below Java program with an empty return statement? |
A. | SHOW Method.. |
B. | No output |
C. | Compiler error |
D. | None |
Answer» B. No output | |
11. |
Choose the correct identifier for a method name in Java. |
A. | 1show |
B. | $hide |
C. | *show$ |
D. | 3_click |
Answer» C. *show$ | |
12. |
In Java, a method name can contain numbers from 2nd character onwards. (TRUE / FALSE). |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
13. |
In Java, a method name can start with ___. |
A. | Alphabet |
B. | Underscore (_) |
C. | Dollar ($) |
D. | All the above |
Answer» E. | |
14. |
In Java, a method name can not start with a ___. |
A. | number |
B. | # (pound) |
C. | - (hyphen) |
D. | All the above |
Answer» E. | |
15. |
Java method signature is a combination of ___. |
A. | Return type |
B. | Method name |
C. | Argument List |
D. | All the above |
Answer» E. | |
16. |
in Java, add a ___ to a constructor to convert it into a method. |
A. | if statement |
B. | static |
C. | return type |
D. | semicolon |
Answer» D. semicolon | |
17. |
State TRUE or FALSE. A Java method can have the same name as the class name. |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
18. |
All Java methods must have a return type. (TRUE / FALSE) |
A. | TRUE |
B. | FALSE |
C. | - |
D. | - |
Answer» B. FALSE | |
19. |
A Java method is comparable to a __ in c language. |
A. | structure |
B. | union |
C. | function |
D. | enum |
Answer» D. enum | |
20. |
Which statement, inserted at line 10, creates an instance of Bar? |
A. | Foo.Bar b = new Foo.Bar(); |
B. | Foo.Bar b = f.new Bar(); |
C. | Bar b = new f.Bar(); |
D. | Bar b = f.new Bar(); |
Answer» C. Bar b = new f.Bar(); | |
21. |
What is the output of this program, Command line execution is done as – “java Output command Line 10 A b 4 N”? |
A. | java |
B. | 10 |
C. | 20 |
D. | b |
Answer» D. b | |
22. |
Which one create an anonymous inner class from within class Bar? |
A. | Boo f = new Boo(24) { }; |
B. | Boo f = new Bar() { }; |
C. | Bar f = new Boo(String s) { }; |
D. | Boo f = new Boo.Bar(String s) { }; |
Answer» C. Bar f = new Boo(String s) { }; | |
23. |
Which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class? |
A. | MyOuter.MyInner m = new MyOuter.MyInner(); |
B. | MyOuter.MyInner mi = new MyInner(); |
C. | MyOuter m = new MyOuter();MyOuter.MyInner mi = m.new MyOuter.MyInner(); |
D. | MyInner mi = new MyOuter.MyInner(); |
Answer» B. MyOuter.MyInner mi = new MyInner(); | |
24. |
After line 8 runs. how many objects are eligible for garbage collection? |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» C. 2 | |
25. |
At what point is the Bar object, created on line 6, eligible for garbage collection? |
A. | after line 12 |
B. | after line 14 |
C. | after line 7, when doBar() completes |
D. | after line 15, when main() completes |
Answer» C. after line 7, when doBar() completes | |
26. |
Where will be the most chance of the garbage collector being invoked? |
A. | After line 9 |
B. | After line 10 |
C. | After line 11 |
D. | Garbage collector never invoked in methodA() |
Answer» E. | |
27. |
When is the B object, created in line 3, eligible for garbage collection? |
A. | after line 5 |
B. | after line 6 |
C. | after line 7 |
D. | There is no way to be absolutely certain. |
Answer» E. | |
28. |
When is the Demo object eligible for garbage collection? |
A. | After line 7 |
B. | After line 8 |
C. | After the start() method completes |
D. | When the instance running this code is made eligible for garbage collection. |
Answer» E. | |
29. |
After line 11 runs, how many objects are eligible for garbage collection? |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» D. 3 | |
30. |
When is the Float object, created in line 3, eligible for garbage collection? |
A. | just after line 5 |
B. | just after line 6 |
C. | just after line 7 |
D. | just after line 8 |
Answer» D. just after line 8 | |
31. |
In the below code, which call to sum() method is appropriate? |
A. | only sum(10) |
B. | only sum(10,20) |
C. | only sum(10) & sum(10,20) |
D. | all of the mentioned |
Answer» E. | |
32. |
Which function is used to perform some action when the object is to be destroyed? |
A. | finalize() |
B. | delete() |
C. | main() |
D. | none of the mentioned |
Answer» B. delete() | |
33. |
Garbage Collection can be controlled by a program? |
A. | True |
B. | False |
C. | May be |
D. | Can't say |
Answer» C. May be | |
34. |
What is not the use of “this” keyword in Java? |
A. | Passing itself to another method |
B. | Calling another constructor in constructor chaining |
C. | Referring to the instance variable when local variable has the same name |
D. | Passing itself to method of the same class |
Answer» E. | |
35. |
What would be the output of the following snippet, if compiled and executed with command line “hello there”? |
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” | |
36. |
What is the output of the following snippet running with “java demo I write java code”? |
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. | |
37. |
What is the output of below snippet run as $ java Demo –length 512 –breadth 2 -h 3 ? |
A. | 2 512 3 |
B. | 2 2 3 |
C. | 512 2 3 |
D. | 512 512 3 |
Answer» D. 512 512 3 | |
38. |
What would be the output of following snippet, if compiled and executed with command line argument “java abc 1 2 3”? |
A. | 1 2 |
B. | 2 3 |
C. | 1 2 3 |
D. | Compilation error |
Answer» C. 1 2 3 | |
39. |
Can a class be declared with a protected modifier. |
A. | True |
B. | False |
C. | May be |
D. | Can't say |
Answer» C. May be | |
40. |
What would be behaviour if the constructor has a return type? |
A. | Compilation error |
B. | Runtime error |
C. | Compilation and runs successfully |
D. | Only String return type is allowed |
Answer» B. Runtime error | |
41. |
What would be the output of the following snippet, if attempted to compile and run this code with command line argument “java abc Rakesh Sharma”? |
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 | |
42. |
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 | |
43. |
What is the output of this program, Command line execution is done as – “java Output This is a command Line”? |
A. | java |
B. | Output |
C. | This |
D. | is |
Answer» D. is | |
44. |
What is the output of this program, Command line exceution is done as – “java Output This is a command Line”? |
A. | java |
B. | is |
C. | This |
D. | command |
Answer» E. | |
45. |
What would be the output of following snippet, if attempted to compile and execute? |
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. | |
46. |
All the variables of interface should be? |
A. | default and final |
B. | default and static |
C. | public, static and final |
D. | protect, static and final |
Answer» D. protect, static and final | |
47. |
All the variables of class should be ideally declared as? |
A. | private |
B. | public |
C. | protected |
D. | default |
Answer» B. public | |
48. |
Which of the following statements are incorrect? |
A. | default constructor is called at the time of object declaration |
B. | Constructor can be parameterized |
C. | finalize() method is called when a object goes out of scope and is no longer needed |
D. | finalize() method must be declared protected |
Answer» D. finalize() method must be declared protected | |
49. |
What is true about constructor? |
A. | It can contain return type |
B. | It can take any number of parameters |
C. | It can have any non access modifiers |
D. | Constructor cannot throw an exception |
Answer» C. It can have any non access modifiers | |
50. |
What is the syntax of abstract class in java? |
A. | abstract A{} |
B. | abstract class A |
C. | abstract class A{} |
D. | abstract class A[] |
Answer» D. abstract class A[] | |