சி
தொகுப்பு சுருக்கம் இல்லை
உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
சி Removed category "நிரலாக்கம்"; Quick-adding category "பொருள் நோக்கு நிரலாக்கம்" (using HotCat) |
சிNo edit summary |
||
வரிசை 2:
மேல்நிலை வகுப்புக்கள் அல்லது [[மீவுவகுப்பு]]க்களில் இருந்து கீழ்நிலை வகுப்புக்களை வரையறை செய்யலாம். உதாரணமாக, வடிவம் என்ற வகுப்பில் இருந்து [[வட்டம்]] என்ற வகுப்பை வரையறை செய்யலாம்.
== பி.எச்.பி எடுத்துகாட்டு ==
பி.எச்.பி இல் [[பொருள் நோக்கு நிரலாக்கம்]] செய்ய முடியும். ஒரு எளிய எடுத்துக்காட்டு கீழே. இந்த எடுத்துக்காட்டில் var, $this ஆகியவை keywords என்பது குறிப்பிடத்தக்கது.
<div style="float:left; width:50%;">
<pre>
<?php
include("C:\Documents and Settings\HP_Owner\Desktop\calc.php");
$c1 = new Calculator;
$c1->set_numbers(1,3);
echo "This sum is: ".$c1->sum()."<br />";
echo "The multiple is: ".$c1->mul()."<br />";
$c2 = new Calculator2;
$c2->set_numbers(5,2);
echo "This sub is: ".$c2->sub()."<br />";
?>
</pre>
</div>
<div style="float:right; width:50%;">
<pre>
This sum is: 4
The multiple is: 3
This sub is: 3
</pre>
</div>
<br style="clear:both;"/>
* calc.php கோப்பு
<pre>
<?php
class Calculator {
//class-wide variables
var $x;
var $y;
//function to gather two numbers
function set_numbers($num1, $num2){
$this->x = $num1;
$this->y = $num2;
}
//function to add numbers together
function sum(){
$ans = $this->x + $this->y;
return $ans;
}
function mul(){
$ans = $this->x * $this->y;
return $ans;
}
}
class Calculator2 extends Calculator {
function sub(){
$ans = $this->x - $this->y;
return $ans;
}
}
?>
</pre>
|