Blogger Information
Blog 5
fans 0
comment 0
visits 4480
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示类成员的三种访问限制符的使用场景
小码哥的博客
Original
640 people have browsed it
<?php

/**

 * Created by PhpStorm.

 * User: dell

 * Date: 2019/10/4

 * Time: 11:31

 */

class 
MyClass{


    
public 
$public 
= 
'Public'
; 
//
父类

    
protected 
$protected 
= 
'Protected'
; 
//
公有变量

    
private 
$private 
= 
'Private'
; 
//
私有变量

    
function 
printHello
(){

        
echo 
$this
->
public
;

        
echo 
'<br>'
;

        
echo 
$this
->
protected
;

        
echo 
'<br>'
;

        
echo 
$this
->
private
;


    
}

}


$obj 
= 
new 
MyClass()
;

echo 
$obj
->
public
;

echo 
'<br>'
;

echo 
$obj
->
printHello
()
;


class 
MyClass2 
extends 
MyClass{

    
protected 
$protected 
= 
'Protected2'
;

    
//
重定义方法

    
function 
printHello
(){

        
echo 
$this
->
public
;

        
echo 
'<br>'
;

        
echo 
$this
->
protected
;


    
}

}


$obj2 
= 
new 
MyClass2()
;

echo 
$obj2
->
public
;

echo 
$obj2
->
printHello
()
;

Correction status:unqualified

Teacher's comments:群中看一下作业要求
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments