Three main features of PHP object-oriented

Source: Internet
Author: User

1. Three main features of object-oriented: encapsulation, inheritance, polymorphism, (abstract (extended))
2, 00A: Analysis, OOD: Design, OOP: programming.
3. Encapsulation: Information concealment, encapsulation, all functions and methods, properties and behaviors in the class are also encapsulated. Three access modifiers public, protected, private are also encapsulated.
4, public common who can use, can also be modified; protected protected only by themselves and descendants can be used and modified; private only own can be used and modified;
5. Inheritance: Extend the contents of the parent class, note that only public and protected-modified content can be inherited, and the private adornment cannot inherit the keyword: extends,
Inheritance in PHP is a single inheritance, that is, there are only 1 class names behind extends, but 1 classes can have an infinite number of subclasses, and the subclasses and the parent classes can only be between 2 classes that have an inheritance relationship.
6. A method that appears in a subclass with the same name as the parent class, which is called rewriting, is a redefinition of the behavior. Overrides can only occur between classes that have an inheritance relationship, which is overridden by the same method name, and has no relation to the parameter.
When overridden, the access modifier can be accessed in a range that is not lower than the access modifier in the parent class. The method for the private adornment cannot be overridden.
code example:

Class zixingche{

  protected $name = ' bike '; 
protected $gulu = 2;
protected $yanse;

Public Function Qiche () {
echo ' can ride ';


Public Function Shache () {
echo ' can brake brake ';


Public Function Jieshao () {
echo ' this is '. $this->name;
Echo ', ';
$this->qiche ();
Echo ', ';
$this->shache ();
}

}
Class Zhediezixingche extends zixingche{

Public Function __construct ($name = ' collapsed from Driving ') {
$this->name = $name;


Public Function Zhedie () {
echo $this->name. ' can be folded ';
}

Public function Jieshao () {
Parent::jieshao ();
Echo ', ';
$this->zhedie ();
}
}

Three main features of PHP object-oriented

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.