PHP

PHP

Object Basics has 19 Questions

Which one of the following is not a valid class name?

ShopProduct
Shopproduct
Shopproduct1
1shopproduct
Fill in the blank with the best option. An Object is a/an ___ of a class.

type
prototype
instance
object
There are two objects- $product1 = new Shop(); $product2 = new Shop(); Which one of the following statements is right about them?

$product1 and $product2 are same objects of the same type generated from a single class.
$product1 and $product2 are different objects of the same type generated from a single class.
$product1 and $product2 are same objects of the different type generated from a single class.
$product1 and $product2 are different objects of the different type generated from a single class.
Which version of PHP introduced the visibility keywords i.e public, private, and protected?

PHP 4
PHP 5
PHP 5.1
PHP 5.3
Which characters is used to access property variables on an object-by-object basis?

::
=
->
.
Code that uses a class, function, or method is often described as the..

client code
user code
object code
class code
Which keyword precedes a method name?

method
function
public
protected
If you omit the visibility keyword in your method declaration, by default the method will be declared as..

public
private
protected
friendly
Which function is used to determine whether the variable's value is either TRUE or FALSE?

boolean()
is_boolean()
bool()
is_bool()
Which version of PHP introduced class type hints?

PHP 4
PHP 4.3
PHP 5
PHP 5.3
Inheritance is the means by which one or more classes can be derived from a/an ___ class.

base
abstract
null
predefined
What will be the output of the following PHP code?
  1. <?php
  2. class MyClass
  3. {
  4. }
  5.  
  6. class NotMyClass
  7. {
  8. }
  9. $a = new MyClass;
  10.  
  11. var_dump($a instanceof MyClass);
  12. var_dump($a instanceof NotMyClass);
  13. ?>

bool(true)

bool(true)

bool(false)

bool(false)

bool(true)

bool(false)

bool(false)

bool(true)

What will be the output of the following PHP code?
  1. <?php
  2. class ParentClass
  3. {
  4. }
  5.  
  6. class MyClass extends ParentClass
  7. {
  8. }
  9.  
  10. $a = new MyClass;
  11.  
  12. var_dump($a instanceof MyClass);
  13. var_dump($a instanceof ParentClass);
  14. ?>

bool(false)

bool(false)

bool(true)

bool(true)

bool(false)

bool(true)

bool(true)

bool(false)

What will be the output of the following PHP code?
  1. <?php
  2. class MyClass
  3. {
  4. }
  5. ?
  6. $a = new MyClass;
  7. var_dump(!($a instanceof stdClass));
  8. ?>

bool(true)
bool(false)
Error
None of the above
What will be the output of the following PHP code?
  1. <?php
  2. interface MyInterface
  3. {
  4. }
  5.  
  6. class MyClass implements MyInterface
  7. {
  8. }
  9.  
  10. $a = new MyClass;
  11.  
  12. var_dump($a instanceof MyClass);
  13. var_dump($a instanceof MyInterface);
  14. ?>

bool(false)

bool(false)

bool(true)

bool(true)

bool(false)

bool(true)

bool(true)

bool(false)

What should be used to refer to a method in the context of a class rather than an object you use?

->
__
$
::
Prior to which version of PHP did constructors took the name of the enclosing class.

PHP 4
PHP 5
PHP 5.3
PHP 5.4
Which method or property can only be accessed from within the enclosing class? Even subclasses have no access.

public
friendly
private
protected
A mutator method is also called as..

Setter
Accessor
Getter
Destructor