0% found this document useful (0 votes)
1 views

prog day2 text

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

prog day2 text

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<?

php
class student{
private $name;
private $gender;
public function setname($name){
$this->name=$name;
echo "Name is ".$name;
echo "<br>";
}
public function setgender($gender){
if($gender == "Male" || $gender == "Female")
{
$this->gender=$gender;
echo "Gender is ".$gender;
}
}
public function getname(){
return $this->name;
}
public function getgender(){
return $this->gender;
}
}
$Moon = new student();
$ Moon ->setname(”ML");
$ Moon ->setgender(”Male");
?>
==================Inheritence- single====================
<?php
class books{
public $title;
public $author;
public $price;
public function __construct($t,$a,$p){
$this->title=$t;
$this->author=$a;
$this->price=$p;
}
public function get_values(){
echo "Title is:".$this->title."<br>“;
echo "Author is:".$this->author."<br>”;
echo “Price is:".$this->price;
}
}
class technicalbooks extends books{
public $publication;
public function set($p){
$this->publication=$p;
}
public function get(){
echo "<br>Publication is:".$this->publication;
}
}
$AWT=new technicalbooks("Advance web Technology", "XYZ","350");
$AWT->set("Mc Grill");
$AWT->get_values();
$AWT->get();
?>
=============interface=====================

<?php
interface Getdata{
public function get();
}
interface Printdata{
public function put();
}
class class1 implements Getdata, Printdata{
public function get(){
echo "Get data method is called";
}
public function put(){
echo "<br>Put data method is called";
}
}
$obj=new class1;
$obj->get();
$obj->put();
?>

============ Traits==============

<?php
trait message1 {
public function msg1() {
echo "Trait 1: msg1 called";
}
}
trait message2 {
public function msg2() {
echo "Trait 2: msg2 called";
}
}
class class1 {
use message1;
}
class class2 {
use message1, message2;
}
$obj = new class1();
$obj->msg1();
echo "<br>";
$obj2 = new class2();
$obj2->msg1();
echo "<br>";
$obj2->msg2();
?>
===========Abstract Class==============

<?php
abstract class class1 {
abstract protected function prefixName($name);
}
class class2 extends class1 {
public function prefixName($name) {
if ($name == ”Moon") {
$prefix = "Mr.";
} elseif ($name == ”Munindra") {
$prefix = ”Mr.";
} else {
$prefix = "";
}
return "{$prefix} {$name}";
}
}
$class = new class2;
echo $class->prefixName(”Munindra");
echo "<br>";
echo $class->prefixName(”Moon");
?>

You might also like