Miscellaneous In Java — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Miscellaneous In Java — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of the following code in Java? `System.out.println(5 / 0);`
Correct Answer: Option C — It throws an ArithmeticException
Detailed Academic Explanation:
It throws an ArithmeticException is the correct answer to “What is the result of the following code in Java? `System.out.println(5 / 0);`”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `break` statement do when used in a `switch` statement in Java?
Correct Answer: Option A — It exits the `switch` statement and continues with the next statement after it
Detailed Academic Explanation:
It exits the `switch` statement and continues with the next statement after it is the correct answer to “What does the `break` statement do when used in a `switch` statement in Java”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which Java keyword is used to explicitly specify that a variable cannot be changed after it is assigned a value?
Correct Answer: Option D — final
Detailed Academic Explanation:
final is the correct answer to “Which Java keyword is used to explicitly specify that a variable cannot be changed after it is assigned a value”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `String.format()` method in Java?
Correct Answer: Option C — To format strings based on a format string and arguments
Detailed Academic Explanation:
To format strings based on a format string and arguments is the correct answer to “What is the purpose of the `String.format()` method in Java”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which Java keyword is used to define a constant interface?
Correct Answer: Option B — final
Detailed Academic Explanation:
final is the correct answer to “Which Java keyword is used to define a constant interface”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `@SuppressWarnings` annotation in Java?
Correct Answer: Option C — To suppress compiler warnings for specific code
Detailed Academic Explanation:
To suppress compiler warnings for specific code is the correct answer to “What is the purpose of the `@SuppressWarnings` annotation in Java”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which collection class does not allow duplicate elements and is typically implemented as a binary tree?
Correct Answer: Option D — TreeSet
Detailed Academic Explanation:
TreeSet is the correct answer to “In Java, which collection class does not allow duplicate elements and is typically implemented as a binary tree”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of the following code in Java? `System.out.println(10 > 5 ? "true" : "false");`
Correct Answer: Option A — true
Detailed Academic Explanation:
true is the correct answer to “What is the result of the following code in Java? `System.out.println(10 > 5 ? "true" : "false");`”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which exception is thrown when an attempt is made to access an array element with an index that is negative or greater than or equal to the array size?
Correct Answer: Option D — ArrayIndexOutOfBoundsException
Detailed Academic Explanation:
ArrayIndexOutOfBoundsException is the correct answer to “In Java, which exception is thrown when an attempt is made to access an array element with an index that is negative or greater than or equal to the array size”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which Java keyword is used to define a subclass that inherits from another class?
Correct Answer: Option C — extends
Detailed Academic Explanation:
extends is the correct answer to “Which Java keyword is used to define a subclass that inherits from another class”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `super` keyword refer to in Java?
Correct Answer: Option B — It refers to the superclass of the current class
Detailed Academic Explanation:
It refers to the superclass of the current class is the correct answer to “What does the `super` keyword refer to in Java”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the purpose of the `transient` keyword when applied to an instance variable?
Correct Answer: Option C — It indicates that the variable should not be serialized
Detailed Academic Explanation:
It indicates that the variable should not be serialized is the correct answer to “In Java, what is the purpose of the `transient` keyword when applied to an instance variable”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet in Java? `System.out.println(Math.pow(2, 3));`
Correct Answer: Option D — 8
Detailed Academic Explanation:
8 is the correct answer to “What is the output of the following code snippet in Java? `System.out.println(Math.pow(2, 3));`”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which Java operator is used to perform a bitwise XOR operation between two integers?
Correct Answer: Option A — ^
Detailed Academic Explanation:
^ is the correct answer to “Which Java operator is used to perform a bitwise XOR operation between two integers”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `instanceof` operator in Java?
Correct Answer: Option D — To check if an object is an instance of a particular class or interface
Detailed Academic Explanation:
To check if an object is an instance of a particular class or interface is the correct answer to “What is the purpose of the `instanceof` operator in Java”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which exception is thrown when an object is accessed before it has been initialized?
Correct Answer: Option C — NullPointerException
Detailed Academic Explanation:
NullPointerException is the correct answer to “In Java, which exception is thrown when an object is accessed before it has been initialized”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which Java class is used to represent an ordered collection of elements?
Correct Answer: Option B — List
Detailed Academic Explanation:
List is the correct answer to “Which Java class is used to represent an ordered collection of elements”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the `synchronized` keyword in Java?
Correct Answer: Option C — To create a synchronized block of code for multithreading
Detailed Academic Explanation:
To create a synchronized block of code for multithreading is the correct answer to “What is the purpose of the `synchronized` keyword in Java”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what does the `this` keyword refer to?
Correct Answer: Option D — It refers to the current instance of the class
Detailed Academic Explanation:
It refers to the current instance of the class is the correct answer to “In Java, what does the `this` keyword refer to”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is true of final class?
Correct Answer: Option D — Final class cannot be inherited
Detailed Academic Explanation:
Final class cannot be inherited is the correct answer to “What is true of final class”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these cannot be declared static?
Correct Answer: Option B — object
Detailed Academic Explanation:
object is the correct answer to “Which of these cannot be declared static”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java 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]); } }
Correct Answer: Option A — Compile time error
Detailed Academic Explanation:
Compile time error is the correct answer to “What will be the output of the following Java 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]); } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many copies of static and class variables are created when 10 objects are created of a class?
Correct Answer: Option A — 1, 10
Detailed Academic Explanation:
1, 10 is the correct answer to “How many copies of static and class variables are created when 10 objects are created of a class”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Can a class be declared with a protected modifier.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “Can a class be declared with a protected modifier.”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java code 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]); } }
Correct Answer: Option D — The snippet compiles, runs and prints "I code"
Detailed Academic Explanation:
The snippet compiles, runs and prints "I code" is the correct answer to “What will be the output of the following Java code 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]); } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if constructor of class A is made private?
Correct Answer: Option B — Objects of class A can be instantiated only within the class where it is declared
Detailed Academic Explanation:
Objects of class A can be instantiated only within the class where it is declared is the correct answer to “What happens if constructor of class A is made private”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following modifier means a particular variable cannot be accessed within the package?
Correct Answer: Option A — private
Detailed Academic Explanation:
private is the correct answer to “Which of the following modifier means a particular variable cannot be accessed within the package”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these methods must be made static?
Correct Answer: Option A — main()
Detailed Academic Explanation:
main() is the correct answer to “Which of these methods must be made static”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java 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] + " "); } }
Correct Answer: Option B — 1 2 3
Detailed Academic Explanation:
1 2 3 is the correct answer to “What will be the output of the following Java 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] + " "); } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the process of defining more than one method in a class differentiated by parameters?
Correct Answer: Option B — Function overloading
Detailed Academic Explanation:
Function overloading is the correct answer to “What is the process of defining more than one method in a class differentiated by parameters”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How can a protected modifier be accessed?
Correct Answer: Option C — accessible within package and outside the package but through inheritance only
Detailed Academic Explanation:
accessible within package and outside the package but through inheritance only is the correct answer to “How can a protected modifier be accessed”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.length()); } }
Correct Answer: Option C — 11
Detailed Academic Explanation:
11 is the correct answer to “What will be the output of the following Java program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.length()); } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of these keywords is used to prevent content of a variable from being modified?
Correct Answer: Option A — final
Detailed Academic Explanation:
final is the correct answer to “Which of these keywords is used to prevent content of a variable from being modified”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java 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); } }
Correct Answer: Option B — 5
Detailed Academic Explanation:
5 is the correct answer to “What will be the output of the following Java 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); } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do we pass command line argument in Eclipse?
Correct Answer: Option A — Arguments tab
Detailed Academic Explanation:
Arguments tab is the correct answer to “How do we pass command line argument in Eclipse”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is the modifier when there is none mentioned explicitly?
Correct Answer: Option D — default
Detailed Academic Explanation:
default is the correct answer to “Which is the modifier when there is none mentioned explicitly”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.charAt(3)); } }
Correct Answer: Option A — I
Detailed Academic Explanation:
I is the correct answer to “What will be the output of the following Java program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.charAt(3)); } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which annotation is used to represent command line input and assigned to correct data type?
Correct Answer: Option D — @Parameter
Detailed Academic Explanation:
@Parameter is the correct answer to “Which annotation is used to represent command line input and assigned to correct data type”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java program? class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } class static_specifier { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + " " + obj2.y); } }
Correct Answer: Option D — 1 5
Detailed Academic Explanation:
1 5 is the correct answer to “What will be the output of the following Java program? class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } class static_specifier { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + " " + obj2.y); } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java 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<xyz.length; n++) { System.out.println(xyz[n]+""); } } }
Correct Answer: Option B — 2 3
Detailed Academic Explanation:
2 3 is the correct answer to “What will be the output of the following Java 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<xyz.length; n++) { System.out.println(xyz[n]+""); } } }”. This question is standard in competitive examination syllabi for Miscellaneous In Java.
💡Key Conceptual Anchor:Miscellaneous In Java
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.