Object Oriented Concept — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Object Oriented Concept — 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
Which one of the following is not a valid class name?
Correct Answer: Option C — 1shopproduct
Detailed Academic Explanation:
You declare a class with the class keyword and an arbitrary class name. Class names can be any combination of numbers and letters, although they must not begin with a number.
💡Key Conceptual Anchor:Object Oriented Concept
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Fill in the blank with the best option. An Object is a/an ________ of a class.
Correct Answer: Option C — instance
Detailed Academic Explanation:
An object is said to be an instance of its class. It is of the type defined by the class.
💡Key Conceptual Anchor:Object Oriented Concept
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which version of PHP introduced the visibility keywords i.e public, private, and protected?
Correct Answer: Option B — PHP 5
Detailed Academic Explanation:
In PHP 4, all properties were declared with var keyword, which is identical in effect to using public. For the sake of backward compatibility, PHP 5 accepts var in place of public for properties.
💡Key Conceptual Anchor:Object Oriented Concept
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which characters is used to access property variables on an object-by-object basis?
Correct Answer: Option C — ->
Detailed Academic Explanation:
Example: $product1->title=”My Life”;
💡Key Conceptual Anchor:Object Oriented Concept
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Code that uses a class, function, or method is often described as the.
Correct Answer: Option A — client code
Detailed Academic Explanation:
Code that uses a class, function, or method is often described as the class’s, function’s, or method’s client or as client code.
💡Key Conceptual Anchor:Object Oriented Concept
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword precedes a method name?
Correct Answer: Option B — function
Detailed Academic Explanation:
A method declaration resembles a function declaration. The function keyword precedes a method name, followed by an optional list of argument variables in parentheses.
💡Key Conceptual Anchor:Object Oriented Concept
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If you omit the visibility keyword in your method declaration, by default the method will be declared as.
Correct Answer: Option A — public
Detailed Academic Explanation:
By declaring a method public, you ensure that it can be invoked from outside of the current object.
💡Key Conceptual Anchor:Object Oriented Concept
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Inheritance is the means by which one or more classes can be derived from a/an ___ class.
Correct Answer: Option A — base
Detailed Academic Explanation:
A class that inherits from another is said to be a subclass of it. This relationship is often described in terms of parents and children. A child class is derived from and inherits characteristics from the parent.
💡Key Conceptual Anchor:Object Oriented Concept
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php class MyClass { } $a = new MyClass; var_dump(!( $a instanceof stdClass )) ; ?>
Correct Answer: Option A — bool(true)
Detailed Academic Explanation:
To check if an object is not an instanceof a class, the logical not operator can be used.
💡Key Conceptual Anchor:Object Oriented Concept
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What should be used to refer to a method in the context of a class rather than an object you use?
Correct Answer: Option D — ::
Detailed Academic Explanation:
Example- parent::__construct()
💡Key Conceptual Anchor:Object Oriented Concept
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Prior to which version of PHP did constructors took the name of the enclosing class.
Correct Answer: Option B — PHP 5
Detailed Academic Explanation:
The new unified constructors use the name __construct(). Using the old syntax, a call to a parent constructor would tie you to that particular class: parent::ShopProduct();
💡Key Conceptual Anchor:Object Oriented Concept
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A mutator method is also called as.
Correct Answer: Option A — Setter
Detailed Academic Explanation:
An accessor method is called getter. The common use of a mutator method is to initialise the value of member variables of a class.
💡Key Conceptual Anchor:Object Oriented Concept
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which version of PHP introduced the static keyword?
Correct Answer: Option B — PHP 5
Detailed Academic Explanation:
The static keyword was introduced with PHP 5. It cannot be used in PHP 4 scripts.
💡Key Conceptual Anchor:Object Oriented Concept
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to access a static method or property from within the same class(rather than from child)?
Correct Answer: Option C — self
Detailed Academic Explanation:
Self is to classes what the $this pseudo-variable is to objects.
💡Key Conceptual Anchor:Object Oriented Concept
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In which of the following circumstance should you use a static reference to a non static method?
Correct Answer: Option A — Making a method call using parent
Detailed Academic Explanation:
Making a method call using parent is the only circumstance in which you should use a static reference to a non-static method.
💡Key Conceptual Anchor:Object Oriented Concept
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following variable cannot be used inside a static method?
Correct Answer: Option A — $this
Detailed Academic Explanation:
By definition, static methods are not invoked in the context of an object. For this reason, static methods and properties are often referred to as class variables and properties.
💡Key Conceptual Anchor:Object Oriented Concept
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does PDO stand for?
Correct Answer: Option D — PHP Data Object
Detailed Academic Explanation:
The PDO class provides a common interface to different database applications.
💡Key Conceptual Anchor:Object Oriented Concept
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to declare a constant property?
Correct Answer: Option A — const
Detailed Academic Explanation:
A constant property is declared with the const keyword. Like global constants, class constants cannot be changed once they are set.
💡Key Conceptual Anchor:Object Oriented Concept
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following is a constant variable?
Correct Answer: Option C — const NAME
Detailed Academic Explanation:
Constants are not prefixed with a dollar sign like regular properties. By convention, they are often named using only uppercase characters
💡Key Conceptual Anchor:Object Oriented Concept
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will happen if you try to set a value to a constant once it has been declared?
Correct Answer: Option C — Parse Error
Detailed Academic Explanation:
You should use constants when your property needs to be available across all instances of a class, and when the property value needs to be fixed and unchanging.
💡Key Conceptual Anchor:Object Oriented Concept
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many of the following can be contained in constants? 1. boolean 2. integer 3. float 4. string
Correct Answer: Option D — 4
Detailed Academic Explanation:
All scalar data i.e boolean, integer, float and string can be contained in constants.
💡Key Conceptual Anchor:Object Oriented Concept
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following class can not be instantiated?
Correct Answer: Option B — abstract class
Detailed Academic Explanation:
An abstract class cannot be instantiated. Instead it defines (and, optionally, partially implements) the interface for any class that might extend it.
💡Key Conceptual Anchor:Object Oriented Concept
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following keywords is used to define an abstract class?
Correct Answer: Option C — abstract
Detailed Academic Explanation:
The introduction of abstract classes was one of the major changes ushered in with PHP 5. Its inclusion in the list of new features was another sign of PHP’s extended commitment to object-oriented design.
💡Key Conceptual Anchor:Object Oriented Concept
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following is the correct abstract method?
Correct Answer: Option D — abstract public function write()
Detailed Academic Explanation:
An abstract method cannot have an implementation. You declare it in the normal way, but end the declaration with a semicolon rather than a method body.
💡Key Conceptual Anchor:Object Oriented Concept
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Atleast how many abstract methods must an abstract class contain?
Correct Answer: Option B — One
Detailed Academic Explanation:
Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract.
💡Key Conceptual Anchor:Object Oriented Concept
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following keyword is used to implement an interface?
Correct Answer: Option D — implements
Detailed Academic Explanation:
A class can implement an interface using the implements keyword in its declaration.
💡Key Conceptual Anchor:Object Oriented Concept
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following methods in the exception class, is used to get a nested exception object?
Correct Answer: Option A — getPrevious()
Detailed Academic Explanation:
getCode() – Get the code integer that was passed to the constructor. getFile() – Get the file in which the exception was generated. getLine() – Get the line number at which the exception was generated.
💡Key Conceptual Anchor:Object Oriented Concept
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following keyword is used in conjunction with an Exception object?
Correct Answer: Option C — throw
Detailed Academic Explanation:
The throw keyword is used in conjunction with an Exception object. It halts execution of the current method and passes responsibility for handling the error back to the calling code.
💡Key Conceptual Anchor:Object Oriented Concept
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword is used to put a stop on inheritance?
Correct Answer: Option D — final
Detailed Academic Explanation:
A final class cannot be subclassed.
💡Key Conceptual Anchor:Object Oriented Concept
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following method is invoked when a value is assigned to an undefined property?
Correct Answer: Option B — __set()
Detailed Academic Explanation:
The __set() method is invoked when client code attempts to assign to an undefined property. It is passed two arguments: the name of the property, and the value the client is attempting to set.
💡Key Conceptual Anchor:Object Oriented Concept
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following method is invoked when an undefined method is called by client code?
Correct Answer: Option D — __call()
Detailed Academic Explanation:
The __call() method is probably the most useful of all the interceptor methods. The __call() method can be useful for delegation. Delegation is the mechanism by which one object passes method invocations on to a second.
💡Key Conceptual Anchor:Object Oriented Concept
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method introduced in PHP 5, is invoked just before an object is garbage collected?
Correct Answer: Option C — __destruct()
Detailed Academic Explanation:
You can use this method to perform any final cleaning up that might be necessary. Imagine, for example, a class that saves itself to a database when so ordered. I could use the __destruct() method to ensure that an instance saves its data when it is deleted.
💡Key Conceptual Anchor:Object Oriented Concept
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword must be added before $first variable on the third line of the above question to make $second and $first as distinct objects in PHP 5?
Correct Answer: Option B — clone
Detailed Academic Explanation:
Clone operates on an object instance, producing a by-value copy.
💡Key Conceptual Anchor:Object Oriented Concept
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code class Person { function getName () { return "Bob" ; } function getAge () { return 44 ; } function __toString () { $desc = $this-> getName(); $desc . = " ( age ". $this-> getAge () .")"; return $desc; } } $person = new Person () ; print $person;
Correct Answer: Option C — BOB (age 44)
Detailed Academic Explanation:
By implementing a __toString() method, you can control how your objects represent themselves when printed. The method is invoked automatically when your object is passed to print or echo, and its return value is substituted.
💡Key Conceptual Anchor:Object Oriented Concept
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
______clone() is run on the _______ object.
Correct Answer: Option D — copied
Detailed Academic Explanation:
__clone() is run on the copied object and not the original.
💡Key Conceptual Anchor:Object Oriented Concept
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? class Checkout { final function totalize () { // calculate bill } } class IllegalCheckout extends Checkout { final function totalize () { // change bill calculation } }
Correct Answer: Option D — PHP Fatal error: Cannot override final method
Detailed Academic Explanation:
A final class cannot be subclassed. Less drastically, a final method cannot be overridden.
💡Key Conceptual Anchor:Object Oriented Concept
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following property scopes is not supported by PHP?
Correct Answer: Option A — friendly
Detailed Academic Explanation:
PHP supports five class property scopes: public, private, protected, final and static.
💡Key Conceptual Anchor:Object Oriented Concept
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following is the right way to define a constant?
Correct Answer: Option D — const PI = ‘3.1415’
Detailed Academic Explanation:
Class constants are created like: const NAME = ‘VALUE’;
💡Key Conceptual Anchor:Object Oriented Concept
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is/are the right way to declare a method? 1. function functionName() { function body } 2. scope function functionName() { function body } 3. method methodName() { method body } 4. scope method methodName() { method body }
Correct Answer: Option C — 1 and 2
Detailed Academic Explanation:
In case of public methods, you can forgo explicitly declaring the scope and just declare the method like you would a function.
💡Key Conceptual Anchor:Object Oriented Concept
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following method scopes is/are not supported by PHP? 1. private 2. final 3. static 4 abstract
Correct Answer: Option D — None of the mentioned
Detailed Academic Explanation:
PHP supports six method scopes: public, private, final, static, protected and abstract.
💡Key Conceptual Anchor:Object Oriented Concept
✓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.