Constructors And Methods — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Constructors And Methods — Part 1 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 return type of a constructor in Java?
Correct Answer: Option C — The same as the class name
Detailed Academic Explanation:
Constructors are special methods in Java used to create objects of a class. They have the same name as the class itself. Unlike other methods, constructors don't have an explicit return type. Their job is to initialize the object's member variables (fields) with values. Therefore, they implicitly return a reference to the newly created object. The correct answer is option C, because it correctly states the return type is implicitly the same as the class name .
💡Key Conceptual Anchor:Constructors And Methods
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the expected output? public class Profile { private Profile(int w) { // line 1 System.out.print(w); } public static Profile() { // line 5 System.out.print (10); } public static void main(String args[]) { Profile obj = new Profile(50); } }
Correct Answer: Option D — Won't compile because of line (5), constructor can't be static
Detailed Academic Explanation:
Only public, protected, private and default (no access modifier) are legal while declaring constructors.
💡Key Conceptual Anchor:Constructors And Methods
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The following code contains one compilation error, find it? public class Test { Test() { } // line 1 static void Test() { this(); } // line 2 public static void main(String[] args) { // line 3 Test(); // line 4 } }
Correct Answer: Option B — At line 2, constructor call
Detailed Academic Explanation:
a constructor call (super() or this() ) must be the first statement inside a constructor. No constructor calls are allowed inside a method. static void Tester() is a method not a constructor.
💡Key Conceptual Anchor:Constructors And Methods
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following options is the best for generating random integer 0 or 1?
Correct Answer: Option C — (int)(Math.random() + 0.5)
Detailed Academic Explanation:
The correct answer is Option C: (int)(Math.random() + 0.5) In Java, to generate a random integer that can be either 0 or 1, you can use the `Math.random()` method, which returns a random double value between 0.0 (inclusive) and 1.0 (exclusive). To convert this into either 0 or 1, you need to add 0.5 to the result and then cast it to an integer using `(int)`. Here's the breakdown of the options: - Option A: `(int)Math.random()` would generate either 0 or a random positive integer, but not necessarily 1. - Option B: `(int)Math.random() + 1` would generate random positive integers starting from 1 and not 0. - Option C: `(int)(Math.random() + 0.5)` adds 0.5 to the random value, making it either 0.5 or 1.5, and then casts it to an integer, resulting in either 0 or 1, which is what you want. - Option D: `(int)(Math.random() + 0.2)` would not reliably generate only 0 or 1; it can produce a range of integers starting from 0.
💡Key Conceptual Anchor:Constructors And Methods
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is Math.floor(3.6)?
Correct Answer: Option A — 3.0
Detailed Academic Explanation:
The method floor gives the largest integer that is less than or equal to the argument.
💡Key Conceptual Anchor:Constructors And Methods
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the expected output? public class Profile { private Profile(int w) { // line 1 System.out.print(w); } public final Profile() { // line 5 System.out.print(10); } public static void main(String args[]) { Profile obj = new Profile(50); } }
Correct Answer: Option B — Won't compile because of line (5); constructor can't be final
Detailed Academic Explanation:
Only public, protected, private and default(no modifier) are legal when declaring constructors.
💡Key Conceptual Anchor:Constructors And Methods
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the expected output? class Animal { Animal() { System.out.println("Animal"); } } class Wild extends Animal{ Wild() { System.out.println("Wild"); super(); } } public class Test { public static void main(String args[]) { Wild wild = new Wild(); } }
Correct Answer: Option D — Compilation Error
Detailed Academic Explanation:
super() call must be the first statement in a constructor.
💡Key Conceptual Anchor:Constructors And Methods
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Determine output of the following program. public class Test{ public static void main(String args[]){ System.out.println( Math.floor( Math.random( ) ) ) ; } }
Correct Answer: Option C — 0.0
Detailed Academic Explanation:
random() is a static method defined in Math class. Syntax: static double random() random() always return a value in the range 0.0 <= Math.random() <1.0 So, taking floor function of any number between above range always yield 0.0. Ex: Math.floor(0.958127101241...) = 0.0 Math.floor(0.05684865565...) = 0.0
💡Key Conceptual Anchor:Constructors And Methods
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the above program? class Num { Num(double x ){ System.out.println( x ) ; } } public class Test extends Num { public static void main(String[] args){ Num num = new Num( 2 ) ; } }
Correct Answer: Option C — Compile time error
Detailed Academic Explanation:
The given program creates a class Num that has a constructor with a double parameter. In the main method, an object of the Num class is created with the value 2, which is passed as a double value. Since 2 is treated as an integer, Java automatically converts it to a double (2.0), and the constructor prints this value. Thus, the output of the program is 2.0.
💡Key Conceptual Anchor:Constructors And Methods
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Determine Output: class A{ public static void method(int i){ System.out.print("Method 1"); } public static int method(String str){ System.out.print("Method 2"); return 0; } } public class Test{ public static void main(String args[]){ A.method(5); } }
Correct Answer: Option A — Method 1
Detailed Academic Explanation:
Overloading depends only on the method or constructor name and its parameter list i.e. method(int i) and method(String str) So, overloading does not depend on access modifiers(public, private, protected), access specifiers(static, final) and return type.
💡Key Conceptual Anchor:Constructors And Methods
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the program? class Test{ public int display(int x, int y){ return ("The sum of x and y is " + x + y); } public static void main(String args[]){ Test test = new Test(); System.out.println(test.display(4,5)); } }
Correct Answer: Option C — does not compile
Detailed Academic Explanation:
Return type of method display is int and we are trying to return string.
💡Key Conceptual Anchor:Constructors And Methods
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The implicit return type of a constructor is
Correct Answer: Option B — A class object in which it is defined.
Detailed Academic Explanation:
Constructors are special methods in Java used to create objects of a class. Unlike other methods, constructors don't have an explicit return type. They don't use keywords like void , int , etc. to specify what they return. Instead, their job is to initialize the object being created, setting initial values for its member variables. When a constructor is called, it automatically returns a newly created object of the class. Therefore, the implicit return type of a constructor is the class object itself. So the correct option is B .
💡Key Conceptual Anchor:Constructors And Methods
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the prototype of the default constructor? public class Test { }
Correct Answer: Option D — public Test( )
Detailed Academic Explanation:
Option A and B are wrong because they use the default access modifier and the access modifier for the class is public (remember, the default constructor has the same access modifier as the class). Option C is wrong. The void makes the compiler think that this is a method specification - in fact if it were a method specification the compiler would spit it out.
💡Key Conceptual Anchor:Constructors And Methods
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the program? class MyClass{ MyClass(){ System.out.print("one"); } public void myMethod(){ this(); System.out.print("two"); } } public class TestClass{ public static void main(String args[]){ MyClass obj = new MyClass(); obj.myMethod(); } }
Correct Answer: Option D — Compilation Error
Detailed Academic Explanation:
The code will result in a compilation error because in the method myMethod, the use of this() is incorrect. In Java, this() is used to call another constructor, but it can only be used in a constructor, not in a method. Using this() in myMethod causes a compilation error. Thus, the program will not compile, and the correct answer is a Compilation Error.
💡Key Conceptual Anchor:Constructors And Methods
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Determine output: public class Test{ public static void main(String args[]){ MyClass obj = new MyClass(); obj.val = 1; obj.call(obj); System.out.println(obj.val); } } class MyClass{ public int val; public void call(MyClass ref){ ref.val++; } }
Correct Answer: Option B — 2
Detailed Academic Explanation:
Step-by-step breakdown: 1. The main method in the Test class creates an instance of MyClass called obj. 2. The val field of obj is set to 1 with obj.val = 1. 3. The call method is invoked on obj with obj itself as the argument: obj.call(obj). 4. Inside the call method, the val field of the passed MyClass instance (ref) is incremented by 1 using ref.val++. Since ref refers to obj, this increments obj.val from 1 to 2. 5. Finally, System.out.println(obj.val) prints the value of obj.val, which is now 2. Therefore, the output of the program is 2 .
💡Key Conceptual Anchor:Constructors And Methods
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
public class MyClass{ } For the above class(MyClass) what is the correct way of declaring constructor?
Correct Answer: Option E — 1 and 3
Detailed Academic Explanation:
Choice A,C are the correct answers. The default access specifier for any constructor is same as the access specifier of class.so the options A and C are correct.
💡Key Conceptual Anchor:Constructors And Methods
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output for the below code? public class A{ int add(int i, int j){ return i+j; } } public class B extends A{ public static void main(String argv[]){ short s = 9; System.out.println(add(s,6)); } }
Correct Answer: Option B — Compile fail due to error on line no 9
Detailed Academic Explanation:
Cannot make a static reference to the non-static method add(int, int) from the type A. The short s is autoboxed correctly, but the add() method cannot be invoked from a static method because add() method is not static.
💡Key Conceptual Anchor:Constructors And Methods
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output for the below code? public class Test{ public static void printValue(int i, int j, int k){ System.out.println("int"); } public static void printValue(byte...b){ System.out.println("long"); } public static void main(String... args){ byte b = 9; printValue(b,b,b); } }
Correct Answer: Option B — int
Detailed Academic Explanation:
Primitive widening uses the smallest method argument possible. (For Example if you pass short value to a method but method with short argument is not available then compiler chooses method with int argument). But in this case compiler will prefer the older style before it chooses the newer style, to keep existing code more robust. var-args method is looser than wider.
💡Key Conceptual Anchor:Constructors And Methods
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output for the below code? class A{ public A(){ System.out.println("A"); } public A(int i){ this(); System.out.println(i); } } class B extends A{ public B(){ System.out.println("B"); } public B(int i){ this(); System.out.println(i+3); } } public class Test{ public static void main (String[] args){ new B(5); } }
Correct Answer: Option A — A B 8
Detailed Academic Explanation:
Constructor of class B call their superclass constructor of class A (public A()), which execute first, and that constructors can be overloaded. Then come to constructor of class B (public B (int i)).
💡Key Conceptual Anchor:Constructors And Methods
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the result of compiling and running the given code? class A{ int b=10; private A(){ this.b=7; } int f(){ return b; } } class B extends A{ int b; } public class Test{ public static void main(String[] args){ A a = new B(); System.out.println(a.f()); } }
Correct Answer: Option A — Compilation Fails
Detailed Academic Explanation:
Choice A is the correct answer. The code does not compile because the constructor of class A is declared as private. This creates a problem when the subclass constructor makes an implicit super() call to the parent class constructor at the time B is instantiated. Since the code does not compile, all the other choices are incorrect. If the constructor of A had not been private, the output would have been 7.
💡Key Conceptual Anchor:Constructors And Methods
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Java 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)); } }
Correct Answer: Option D — Runtime Error
Detailed Academic Explanation:
Let's break down why the answer is a Runtime Error . The problem lies within the `func` method of the `recursion` class. It's trying to use recursion , which means a function calling itself. Here's the critical issue: The `func` method calls itself (`func(n - 1)`) without a base case . A base case is a condition that stops the recursive calls. Without a base case, the function keeps calling itself again and again. Imagine `func(12)` is called. It then calls `func(11)`, then `func(10)`, and so on. This continues indefinitely, each call placing another "frame" onto the call stack (memory used to track function calls). Eventually, the call stack runs out of space. This is called a StackOverflowError . StackOverflowError is a type of Runtime Error . Because the error happens while the program is running (not during compilation), it's a runtime error. Therefore, the correct answer is Option D: Runtime Error .
💡Key Conceptual Anchor:Constructors And Methods
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a constructor in Java?
Correct Answer: Option A — A special method to create instances of classes
Detailed Academic Explanation:
A special method to create instances of classes is the correct answer to “What is a constructor in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to define a method in Java?
Correct Answer: Option D — public
Detailed Academic Explanation:
public is the correct answer to “Which keyword is used to define a method in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which method is automatically called when an object is created?
Correct Answer: Option D — constructor()
Detailed Academic Explanation:
constructor() is the correct answer to “In Java, which method is automatically called when an object is created”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is method overloading in Java?
Correct Answer: Option A — Defining multiple methods with the same name in the same class
Detailed Academic Explanation:
Defining multiple methods with the same name in the same class is the correct answer to “What is method overloading in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the "void" keyword indicate in a method declaration?
Correct Answer: Option A — The method does not return any value
Detailed Academic Explanation:
The method does not return any value is the correct answer to “What does the "void" keyword indicate in a method declaration”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which access modifier is used for a method that can be accessed from any class in the same package?
Correct Answer: Option D — package-private (no modifier)
Detailed Academic Explanation:
package-private (no modifier) is the correct answer to “Which access modifier is used for a method that can be accessed from any class in the same package”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the "this" keyword in Java constructors and methods?
Correct Answer: Option A — To refer to the current instance of the class
Detailed Academic Explanation:
To refer to the current instance of the class is the correct answer to “What is the purpose of the "this" keyword in Java constructors and methods”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to prevent method overriding in Java?
Correct Answer: Option A — final
Detailed Academic Explanation:
final is the correct answer to “Which keyword is used to prevent method overriding in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct syntax to call a method named "myMethod" from an object "myObject"?
Correct Answer: Option A — myObject.myMethod()
Detailed Academic Explanation:
myObject.myMethod() is the correct answer to “What is the correct syntax to call a method named "myMethod" from an object "myObject"”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is called when an object is garbage collected in Java?
Correct Answer: Option A — finalize()
Detailed Academic Explanation:
finalize() is the correct answer to “Which method is called when an object is garbage collected in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, can a constructor have a return type?
Correct Answer: Option A — No, constructors do not have a return type
Detailed Academic Explanation:
No, constructors do not have a return type is the correct answer to “In Java, can a constructor have a return type”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is method overriding in Java?
Correct Answer: Option A — Defining a new method with the same name in a subclass
Detailed Academic Explanation:
Defining a new method with the same name in a subclass is the correct answer to “What is method overriding in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, what is the purpose of the "super" keyword in a constructor?
Correct Answer: Option A — To call the superclass constructor
Detailed Academic Explanation:
To call the superclass constructor is the correct answer to “In Java, what is the purpose of the "super" keyword in a constructor”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a "static" method in Java?
Correct Answer: Option A — A method that belongs to the class rather than an instance
Detailed Academic Explanation:
A method that belongs to the class rather than an instance is the correct answer to “What is a "static" method in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a parameterized constructor in Java?
Correct Answer: Option B — A constructor with parameters that initialize object properties
Detailed Academic Explanation:
A constructor with parameters that initialize object properties is the correct answer to “What is a parameterized constructor in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to call the constructor of the superclass in a subclass constructor?
Correct Answer: Option A — super
Detailed Academic Explanation:
super is the correct answer to “Which keyword is used to call the constructor of the superclass in a subclass constructor”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of method parameters in Java?
Correct Answer: Option A — To pass values into a method
Detailed Academic Explanation:
To pass values into a method is the correct answer to “What is the purpose of method parameters in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, which keyword is used to define an abstract method?
Correct Answer: Option A — abstract
Detailed Academic Explanation:
abstract is the correct answer to “In Java, which keyword is used to define an abstract method”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is method chaining in Java?
Correct Answer: Option A — Calling multiple methods on the same object in a single line
Detailed Academic Explanation:
Calling multiple methods on the same object in a single line is the correct answer to “What is method chaining in Java”. This question is standard in competitive examination syllabi for Constructors And Methods.
💡Key Conceptual Anchor:Constructors And Methods
✓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.