214 quizzes found.

What is wrong with the following code?

<?phpfunction duplicate($obj) {$newObj = $obj;return $newObj;}$a = new MyClass();$a_copy = duplicate($a);$a->setValue(10);$a_copy->setValue(20);?>
  1. You must use return &$newObj instead
  2. There is nothing wrong with this code
  3. duplicate() must accept its parameter by reference
  4. You must use the clone operator to make a copy of an object
  5. duplicate() must return a reference

Choose 1 answers

How can you modify the copy of an object during a clone operation?

  1. Put the logic in the object's constructor to alter the values
  2. Implment your own function to do object copying
  3. Implement the object's __clone() method
  4. Implement __get() and __set() methods with the correct logic
  5. Implement the __copy() method with the correct logic

Choose 1 answers

What is the primary difference between a method declared as static and a normal method?

  1. Static methods can only be called using the :: syntax and never from an instance
  2. Static methods do not provide a reference to $this
  3. Static methods cannot be called from within class instances
  4. Static methods don't have access to the self keyword
  5. There is no functional difference between a static and non-static method

Choose 1 answers

What is the output of the following script?

<?phpclass ClassOne { protected $a = 10; public function changeValue($b) { $this->a = $b; }}class ClassTwo extends ClassOne { protected $b = 10; public function changeValue($b) { $this->b = 10; parent::changeValue($this->a + $this->b); } public function displayValues() { print "a: {$this->a}, b: {$this->b}\n"; }}$obj = new ClassTwo();$obj->changeValue(20);$obj->changeValue(10);$obj->displayValues();?>
  1. a: 30, b: 30
  2. a: 30, b: 20
  3. a: 30, b: 10
  4. a: 20, b: 20
  5. a: 10, b: 10

Choose 1 answers

The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used.

  1. final
  2. protected
  3. incomplete
  4. abstract
  5. implements

Choose 1 answers