Java Techies- Solution for All
Encapsulation
- Encapsulation is to ascertain that each part of an application is seperate and doesn't interfere with any others.
- When defining a property in a class, you must specify whether it's public, private, or protected.
- Public properties are available to all parts of a PHP script, both inside and outside the class definition, and their values can be changed in the same way as any variable.
- Protected and private properties are invisible from external scripts, so they cannot be changed arbitrarily.
Example :
<?php class Encapsulation { private function display() { echo " This is private Function"; } } class Test extends Encapsulation { function display() { echo "This is sub class"; } } $obj=new Encapsulation(); $obj->display(); ?>
Output :
Fatal error: Call to private method Encapsulation::display()