Comment on Tutorial - public, protected, and private Properties in PHP By Andi, Stig and Derick



Comment Added by : Neeraj

Comment Added at : 2010-10-22 07:23:56

Comment on Tutorial : public, protected, and private Properties in PHP By Andi, Stig and Derick
i disagree that private variables can be accessed from derived class. The below code runs perfectly.

<?php
class a{

private $name;

public function setval($val){
$this->name = $val;
echo $this->name." 1<BR>";
}
}

class b extends a{

private $name1;

public function setval($val){
$this->name = $val;
echo $this->name." 2<BR>";
}
}

class c extends b{
private $name2;

public function setval($val){
$this->name = $val;
echo $this->name." 3<BR>";
}
}

class d extends c{
private $name3;

public function setval($val){
$this->name = $val;
echo $this->name." 4<BR>";
}
}

$obj1 = new a();
$obj1->setval(5);
$obj2 = new b();
$obj2->setval(10);
$obj3 = new c();
$obj3->setval(20);
$obj4 = new d();
$obj4->setval(30);
?>


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. I have a problem , i cant see the Microsoft.Office
View Tutorial          By: Japz at 2012-01-16 09:51:11

2. very useful article. every jsp resource will get g
View Tutorial          By: pechirani at 2011-06-29 04:00:49

3. but how is the string concatenation done with the
View Tutorial          By: Vipin at 2009-05-09 03:08:51

4. Very well explained Thanks.
View Tutorial          By: Anthony at 2012-12-12 00:20:39

5. teacher namin na si Engr. Lumasag nakakasira ng ba
View Tutorial          By: rossy at 2011-10-06 06:12:53

6. its superb
View Tutorial          By: chotu jain at 2011-05-24 08:47:22

7. Thanks. But I've also had to use $JAVA_HOME/jre/li
View Tutorial          By: Alex at 2010-03-15 04:17:09

8. Thanks a ton Ganesh...
View Tutorial          By: Anonymous at 2012-01-25 11:20:40

9. Thanks For This Explanatory Tutorial .
View Tutorial          By: Pralay at 2013-06-15 03:50:26

10. site is really good.explaining the concept with ni
View Tutorial          By: reddy chakri india at 2009-03-10 00:20:00