

MCQOPTIONS
Saved Bookmarks
This section includes 194 Mcqs, each offering curated multiple-choice questions to sharpen your Php knowledge and support exam preparation. Choose a topic below to get started.
51. |
You access an object’s properties and methods using the ....... operator ( a hyphen followed by a greater than symbol).%! |
A. | >> |
B. | => |
C. | -> |
D. | none of above |
Answer» D. none of above | |
52. |
¬¨‚Ä . . . . . . is a class which can only be instantiated once. You can effectively only have one object per . . . . . class in an application.%! |
A. | Constructor, Singleton |
B. | Singleton, Constructor |
C. | Singleton, Singleton |
D. | Loader, Loader |
Answer» D. Loader, Loader | |
53. |
All PHP classes come with a default constructor that takes .... arguments.%! |
A. | one |
B. | two |
C. | three |
D. | no |
Answer» E. | |
54. |
You can invoke class constructors that don’t have any relation to the instantiated object by simply prefacing _constructor with the class name like.%! |
A. | classname::__construct() |
B. | classname:__construct() |
C. | classname=>__construct() |
D. | classname->__construct() |
Answer» B. classname:__construct() | |
55. |
The visibility of a property or method can be defined by prefixing the declaration with the keywords public, protected or private. Class members declared public can be accessed everywhere. Members declared protected can be accessed only within the class itself and by inherited classes. Members declared as private are not accessible.%! |
A. | True |
B. | False |
Answer» C. | |
56. |
Unlike constructors, you cannot pass information to a destructor, because you are never sure when its going to be run.%! |
A. | TRUE |
B. | FALSE |
Answer» B. FALSE | |
57. |
Once a class has been defined, objects can be created from the class with the ....... keyword.%! |
A. | new object |
B. | construct |
C. | new |
D. | both A and C |
Answer» D. both A and C | |
58. |
Constructor and destructor methods have no . . . . . . and are called automatically - they cannot be called explicitly and consequently their declarations need no access specifier.¬¨‚Ä%! |
A. | parameters |
B. | destructor |
C. | return value |
D. | aproval |
Answer» D. aproval | |
59. |
PHP makes it possible to automatically execute code when a new instance of a class is created, using a special class method called a ........¬¨‚Ä%! |
A. | destructor |
B. | constructor |
C. | friend |
D. | initial |
Answer» C. friend | |
60. |
What will be the output of the following PHP code?title}: " .$shopProduct->getProducer() ." ({$shopProduct->price})n"; print $str; }}$product1 = new ShopProduct( "My Antonia", "Willa", "Cather", 5.99 );$writer = new ShopProductWriter();$writer->write( $product1 );?>%! |
A. | Error |
B. | Cather: Willa My Antonia (5.99) |
C. | Willa: Cather My Antonia (5.99) |
D. | My Antonia: Willa Cather (5.99) |
Answer» E. | |
61. |
Prior to which version of PHP did constructors took the name of the enclosing class.%! |
A. | PHP 4 |
B. | PHP 5 |
C. | PHP 5.3 |
D. | PHP 5.4 |
Answer» C. PHP 5.3 | |
62. |
In which of the following circumstance should you use a static reference to a non static method?%! |
A. | Making a method call using parent |
B. | Making a method call using child |
C. | Making an object call using parent |
D. | Making an object call using child |
Answer» B. Making a method call using child | |
63. |
Which one of the following is a constant variable?%! |
A. | const $name |
B. | const $NAME |
C. | constant NAME |
D. | const NAME |
Answer» E. | |
64. |
Which one of the following is the correct abstract method?%! |
A. | public function write() |
B. | abstract function write() |
C. | abstract public write(); |
D. | abstract public function write(); |
Answer» E. | |
65. |
Which one of the following keyword is used in conjunction with an Exception object?%! |
A. | throws |
B. | exception |
C. | throw |
D. | final |
Answer» D. final | |
66. |
Which method introduced in PHP 5, is invoked just before an object is garbage collected?%! |
A. | __collect() |
B. | __garbage() |
C. | __destruct() |
D. | __destructor() |
Answer» D. __destructor() | |
67. |
Which method is invoked when an undefined property is accessed ?%! |
A. | __get() |
B. | __isset() |
C. | __unset() |
D. | __undefined() |
Answer» B. __isset() | |
68. |
Which version of PHP introduced the instanceof keyword?%! |
A. | PHP 4 |
B. | PHP 5 |
C. | PHP 5.3 |
D. | PHP 6 |
Answer» C. PHP 5.3 | |
69. |
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 }%! |
A. | Only 2 |
B. | Only 4 |
C. | 1 and 2 |
D. | 3 and 4 |
Answer» D. 3 and 4 | |
70. |
Which one of the following property scopes is not supported by PHP?%! |
A. | friendly |
B. | final |
C. | public |
D. | static |
Answer» B. final | |
71. |
The class from which the child class inherits is called.1. Child class2. Parent class3. Super class4. Base class%! |
A. | Only 1 |
B. | 2, 3 and 4 |
C. | Only 3 |
D. | 2 and 4 |
Answer» E. | |
72. |
Which keyword is used to refer to properties or methods within the class itself?%! |
A. | private |
B. | public |
C. | protected |
D. | $this |
Answer» E. | |
73. |
*$_In . . . . . constructors, it is important to remember that you have to call the parent constructor explicitly.? |
A. | Singleton |
B. | secure |
C. | public |
D. | subclass |
Answer» E. | |
74. |
*$_Which method is invoked when an undefined property is accessed ?? |
A. | __get() |
B. | __isset() |
C. | __unset() |
D. | __undefined() |
Answer» B. __isset() | |
75. |
*$_Which one of the following keyword is used in conjunction with an Exception object?? |
A. | throws |
B. | exception |
C. | throw |
D. | final |
Answer» D. final | |
76. |
*$_Which method introduced in PHP 5, is invoked just before an object is garbage collected?? |
A. | __collect() |
B. | __garbage() |
C. | __destruct() |
D. | __destructor() |
Answer» D. __destructor() | |
77. |
*$_What will be the output of the following PHP code?title}: " .$shopProduct->getProducer() ." ({$shopProduct->price})n"; print $str; }}$product1 = new ShopProduct( "My Antonia", "Willa", "Cather", 5.99 );$writer = new ShopProductWriter();$writer->write( $product1 );?>? |
A. | Error |
B. | Cather: Willa My Antonia (5.99) |
C. | Willa: Cather My Antonia (5.99) |
D. | My Antonia: Willa Cather (5.99) |
Answer» E. | |
78. |
*$_Which one of the following is a constant variable?? |
A. | const $name |
B. | const $NAME |
C. | constant NAME |
D. | const NAME |
Answer» E. | |
79. |
*$_Which one of the following is the correct abstract method?? |
A. | public function write() |
B. | abstract function write() |
C. | abstract public write(); |
D. | abstract public function write(); |
Answer» E. | |
80. |
*$_Prior to which version of PHP did constructors took the name of the enclosing class.? |
A. | PHP 4 |
B. | PHP 5 |
C. | PHP 5.3 |
D. | PHP 5.4 |
Answer» C. PHP 5.3 | |
81. |
*$_In which of the following circumstance should you use a static reference to a non static method?? |
A. | Making a method call using parent |
B. | Making a method call using child |
C. | Making an object call using parent |
D. | Making an object call using child |
Answer» B. Making a method call using child | |
82. |
*$_Which feature allows us to call more than one method or function of the class in single instruction?? |
A. | Typecasting |
B. | Method Including |
C. | Method adding |
D. | Method chaining |
Answer» E. | |
83. |
*$_The class from which the child class inherits is called.1. Child class2. Parent class3. Super class4. Base class? |
A. | Only 1 |
B. | 2, 3 and 4 |
C. | Only 3 |
D. | 2 and 4 |
Answer» E. | |
84. |
*$_Which keyword is used to refer to properties or methods within the class itself?? |
A. | private |
B. | public |
C. | protected |
D. | $this |
Answer» E. | |
85. |
*$_Which version of PHP introduced the instanceof keyword?? |
A. | PHP 4 |
B. | PHP 5 |
C. | PHP 5.3 |
D. | PHP 6 |
Answer» C. PHP 5.3 | |
86. |
*$_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 }? |
A. | Only 2 |
B. | Only 4 |
C. | 1 and 2 |
D. | 3 and 4 |
Answer» D. 3 and 4 | |
87. |
*$_Which one of the following property scopes is not supported by PHP?? |
A. | friendly |
B. | final |
C. | public |
D. | static |
Answer» B. final | |
88. |
*/*_Object-oriented code tries to minimize dependencies by moving responsibility for handling tasks away from _______ and toward the objects in the system.? |
A. | server code |
B. | client code |
C. | machine code |
D. | procedural code |
Answer» C. machine code | |
89. |
*/*_You use the get_class_methods() function to return the names of all the methods in the class. Which function will you use to print it on the screen?? |
A. | printf() |
B. | print_ar |
C. | print_r |
D. | echo |
Answer» D. echo | |
90. |
*/*_Which function was introduced to help automate the inclusion of class files?? |
A. | __load() |
B. | __preload() |
C. | __autoload() |
D. | __inload() |
Answer» D. __inload() | |
91. |
*/*_Which one of the following is the correct way of declaring a namespace?? |
A. | namespace my; |
B. | namespace my(); |
C. | my namespace; |
D. | namespace(my); |
Answer» B. namespace my(); | |
92. |
*/*_A valid class name starts with a ......., followed by any number of letters, numbers, or underscores.1. Number2. Letter3. Period4. Underscore? |
A. | Option 1 and 4 |
B. | Option 2 and 3 |
C. | Option 3 and 4 |
D. | Option 1 and 3 |
Answer» C. Option 3 and 4 | |
93. |
*/*_Which one of the following statements is true about sequence diagrams?? |
A. | A sequence diagram is class based |
B. | A sequence diagram presents the participants of a system from right to left |
C. | The vertical broken lines represent the lifetime of the class in the system |
D. | A sequence diagram is object based |
Answer» E. | |
94. |
*/*__________ are used in class diagrams to describe the way in which specific elements should be used.? |
A. | Attributes |
B. | Constraints |
C. | Constants |
D. | Class Names |
Answer» C. Constants | |
95. |
*/*_Polymorphism is also known as______? |
A. | switch |
B. | overact |
C. | encapsulation |
D. | class switching |
Answer» E. | |
96. |
*/*_Which function is used to determine whether the variable’s value is either TRUE or FALSE?? |
A. | boolean() |
B. | is_boolean() |
C. | bool() |
D. | is_bool() |
Answer» E. | |
97. |
*/*_What should be used to refer to a method in the context of a class rather than an object you use?? |
A. | -> |
B. | __ |
C. | $ |
D. | :: |
Answer» E. | |
98. |
*/*_Which keyword is used to access a static method or property from within the same class(rather than from child)?? |
A. | static |
B. | strat |
C. | self |
D. | set |
Answer» D. set | |
99. |
*/*_Which keyword is used to declare a constant property?? |
A. | const |
B. | con |
C. | constant |
D. | _constant |
Answer» B. con | |
100. |
*/*_Which one of the following keywords is used to define an abstract class?? |
A. | extends |
B. | implements |
C. | abstract |
D. | new |
Answer» D. new | |