What are the values of $a in $obj_one and $obj_two when this script is executed?
<?php
class myClass {
private $a;
public function __construct() {
$this->a = 10;
}
public function printValue() {
print "The Value is: {$this->a}\n";
}
public function changeValue($val, $obj = null) {
if(is_null($obj)) {
$this->a = $val;
} else {
$obj->a = $val;
}
}
public function getValue() {
return $this->a;
}
}
$obj_one = new myClass();
$obj_two = new myClass();
$obj_one->changeValue(20, $obj_two);
$obj_two->changeValue($obj_two->getValue(), $obj_one);
$obj_two->printValue();
$obj_one->printValue();
?>
Answer...
10,20
You cannot modify private member variables of a different class
20,20
10,10
20,10
MY ans: 20, 20
Please answer through the comments I will make it publish on blog..............
[Thursday, February 21, 2008
|
0
comments
]
Popular Posts
- Elgg : The most popular open source social networking platform
- function to check whether the year given is a leap year or not
- php Questions
- Php Questions
- Php Questions
- errrors in php
- OOP in PHP5
- mysql
- Ansewer This What is the output of the following code?
- How to find out the Mysql storage engine type of a table.
0 comments
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.