Excel數(shù)字變?yōu)槲谋靖袷降霓D(zhuǎn)換方法
879
2023-11-15
<?php
class UserName
{
//定義屬性
private $name;
//定義構(gòu)造函數(shù)
function __construct( $name )
{
$this->name = $name; //這里已經(jīng)使用了this指針
}
//析構(gòu)函數(shù)
function __destruct(){}
//打印用戶名成員函數(shù)
function printName()
{
print( $this->name ); //又使用了this指針
}
}
//實(shí)例化對(duì)象
$nameObject = new UserName( "heiyeluren" );
//執(zhí)行打印
$nameObject->printName(); //輸出: heiyeluren
//第二次實(shí)例化對(duì)象
$nameObject = new UserName( "PHP" );
//執(zhí)行打印
$nameObject->printName(); //輸出:PHP
?>
<?php
class Counter
{
//定義屬性,包括一個(gè)靜態(tài)變量
private static $firstCount = ;
private $lastCount;
//構(gòu)造函數(shù)
function __construct()
{
$this->lastCount = ++selft::$firstCount; //使用self來(lái)調(diào)用靜態(tài)變量,使用self調(diào)用必須使用::(域運(yùn)算符號(hào))
}
//打印最次數(shù)值
function printLastCount()
{
print( $this->lastCount );
}
}
//實(shí)例化對(duì)象
$countObject = new Counter();
$countObject->printLastCount(); //輸出
?>
<?php
//基類
class Animal
{
//基類的屬性
public $name; //名字
//基類的構(gòu)造函數(shù)
public function __construct( $name )
{
$this->name = $name;
}
}
//派生類
class Person extends Animal //Person類繼承了Animal類
{
public $personSex; //性別
public $personAge; //年齡
//繼承類的構(gòu)造函數(shù)
function __construct( $personSex, $personAge )
{
parent::__construct( "heiyeluren" ); //使用parent調(diào)用了父類的構(gòu)造函數(shù)
$this->personSex = $personSex;
$this->personAge = $personAge;
}
function printPerson()
{
print( $this->name. " is " .$this->personSex. ",this year " .$this->personAge );
}
}
//實(shí)例化Person對(duì)象
$personObject = new Person( "male", "");
//執(zhí)行打印
$personObject->printPerson(); //輸出:heiyeluren is male,this year
?>
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請(qǐng)用戶自負(fù)。本站信息來(lái)自網(wǎng)絡(luò)收集整理,版權(quán)爭(zhēng)議與本站無(wú)關(guān)。您必須在下載后的24個(gè)小時(shí)之內(nèi),從您的電腦或手機(jī)中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請(qǐng)支持正版,購(gòu)買注冊(cè),得到更好的正版服務(wù)。我們非常重視版權(quán)問(wèn)題,如有侵權(quán)請(qǐng)郵件[admin@lxwl520.com]與我們聯(lián)系進(jìn)行刪除處理。敬請(qǐng)諒解!