PHP OOP Classes and Objects
by TechVidvan Team
Program 1
<?php
class MyClass
{
public $m,$n,$r; // instacne
function add()
{
echo "<center>";
$this->r=$this->m + $this->n;
echo "Addition is".$this->r;
echo "</center>";
return $this->r;
}
function sub()
{
echo "<center>";
$this->r=$this->m - $this->n;
echo "Subtraction is".$this->r;
echo "</center>";
return $this->r;
}
}
$obj1=new MyClass();
//$obj1->display();
$obj1->m=600;
$obj1->n=500;
// $a=$obj1->add();
$obj1->add();
echo "<br>";
$obj1->sub();
// echo "<center>";
// echo "Addition is: ".$a;
// echo "</center>";
Tags: classes and object in phpclasses and objectsPHPphp classes and objectsphp object oriented programmingphp oopphp oop classes and objectsphp practicalphp program
TechVidvan Team
TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.