Skip to main content

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
Question 1 of 40
★ FPSC ★ PPSC

What is the result of the following code in Java? `System.out.println(5 / 0);`

Question 2 of 40
★ FPSC ★ PPSC

What does the `break` statement do when used in a `switch` statement in Java?

Question 3 of 40
★ FPSC ★ PPSC

Which Java keyword is used to explicitly specify that a variable cannot be changed after it is assigned a value?

Question 4 of 40
★ FPSC ★ PPSC

What is the purpose of the `String.format()` method in Java?

Question 5 of 40
★ FPSC ★ PPSC

Which Java keyword is used to define a constant interface?

Question 6 of 40
★ FPSC ★ PPSC

What is the purpose of the `@SuppressWarnings` annotation in Java?

Question 7 of 40
★ FPSC ★ PPSC

In Java, which collection class does not allow duplicate elements and is typically implemented as a binary tree?

Question 8 of 40
★ FPSC ★ PPSC

What is the result of the following code in Java? `System.out.println(10 > 5 ? "true" : "false");`

Question 9 of 40
★ 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?

Question 10 of 40
★ FPSC ★ PPSC

Which Java keyword is used to define a subclass that inherits from another class?

Question 11 of 40
★ FPSC ★ PPSC

What does the `super` keyword refer to in Java?

Question 12 of 40
★ FPSC ★ PPSC

In Java, what is the purpose of the `transient` keyword when applied to an instance variable?

Question 13 of 40
★ FPSC ★ PPSC

What is the output of the following code snippet in Java? `System.out.println(Math.pow(2, 3));`

Question 14 of 40
★ FPSC ★ PPSC

Which Java operator is used to perform a bitwise XOR operation between two integers?

Question 15 of 40
★ FPSC ★ PPSC

What is the purpose of the `instanceof` operator in Java?

Question 16 of 40
★ FPSC ★ PPSC

In Java, which exception is thrown when an object is accessed before it has been initialized?

Question 17 of 40
★ FPSC ★ PPSC

Which Java class is used to represent an ordered collection of elements?

Question 18 of 40
★ FPSC ★ PPSC

What is the purpose of the `synchronized` keyword in Java?

Question 19 of 40
★ FPSC ★ PPSC

In Java, what does the `this` keyword refer to?

Question 20 of 40
★ FPSC ★ PPSC

What is true of final class?

Question 21 of 40
★ FPSC ★ PPSC

Which of these cannot be declared static?

Question 22 of 40
★ 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]); } }

Question 23 of 40
★ FPSC ★ PPSC

How many copies of static and class variables are created when 10 objects are created of a class?

Question 24 of 40
★ FPSC ★ PPSC

Can a class be declared with a protected modifier.

Question 25 of 40
★ 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]); } }

Question 26 of 40
★ FPSC ★ PPSC

What happens if constructor of class A is made private?

Question 27 of 40
★ FPSC ★ PPSC

Which of the following modifier means a particular variable cannot be accessed within the package?

Question 28 of 40
★ FPSC ★ PPSC

Which of these methods must be made static?

Question 29 of 40
★ 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] + " "); } }

Question 30 of 40
★ FPSC ★ PPSC

What is the process of defining more than one method in a class differentiated by parameters?

Question 31 of 40
★ FPSC ★ PPSC

How can a protected modifier be accessed?

Question 32 of 40
★ 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()); } }

Question 33 of 40
★ FPSC ★ PPSC

Which of these keywords is used to prevent content of a variable from being modified?

Question 34 of 40
★ 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); } }

Question 35 of 40
★ FPSC ★ PPSC

How do we pass command line argument in Eclipse?

Question 36 of 40
★ FPSC ★ PPSC

Which is the modifier when there is none mentioned explicitly?

Question 37 of 40
★ 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)); } }

Question 38 of 40
★ FPSC ★ PPSC

Which annotation is used to represent command line input and assigned to correct data type?

Question 39 of 40
★ 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); } }

Question 40 of 40
★ 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]+""); } } }

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 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.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →