SlideShare a Scribd company logo
OOPS Characteristics (With Examples in PHP)
OOPS CONCEPTS
Rajishma T
rajishmatnair@gmail.com
www.facebook.com/ Rajishma T
Nair
twitter.com/username
in.linkedin.com/in/profilename
9020217968
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
CLASS
 A class is an expanded concept of a data,it
can hold both data and functions.
A class is the blueprint for your object.
A class, for example, is like a blueprint for a
house. It defines the shape of the house on
paper, with relationships between the
different parts of the house clearly defined
and planned out, even though the house
doesn’t exist.
visibility
The visibility of class members, (properties,
methods), relates to how that member may be
manipulated within, or from outside the class.
 private:private members are accessible only in
the class itself.
Public:public members are accessible outside the
class(anywhere).
Protected:protected members are accessible in the
same package,and the subclasses of the class and
inside the class.
OOPS CHARACTERESTICS
 data encapsulation.
 inheritance.
Polymorphism.
Data abstraction.
ENCAPSULATION
The wrapping up of a data and functions into a single
unit(which is called class).
Encapsulation means that some or all of an objects
internal structure is hidden from the outside world.
Hidden information may only be accessed through
the object’s public interface.
example
<?php
class MyClass
{
public $prop1 = "I'm a class property!";
public function setProperty($newval)
{
$this->prop1 = $newval;
}
public function getProperty()
{
return $this->prop1 . "<br />";
}
}
$obj = new MyClass;
echo $obj->getProperty(); // Get the property value
$obj->setProperty("I'm a new property value!"); // Set a new one
echo $obj->getProperty(); // Read it out again to show the change
?>
Output
• http://localhost/phpWorkspace/oops.php/class.php
INHERITANCE
• When you want to create a new class and there is
already a class that includes some of the code
that you want, you can derive your new class
from the existing class.
• A class that is derived from another class is called
a subclass (also a derived class, extended class, or
child class).
• The class from which the subclass is derived is
called a superclass (also a base class or a parent
class).
TYPES OF INHERITANCE
• Single Inheritance
• Hierarchical Inheritance
• Multi Level Inheritance
• Hybrid Inheritance
• Multiple Inheritance
SINGLE INHERITANCE
• when a single derived class is created from a
single base class then the inheritance is called
as single inheritance.
HIERARCHICAL INHERITANCE
• when more than one derived class are created
from a single base class, then that inheritance
is called as hierarchical inheritance.
MULTILEVEL INHERITANCE
• when a derived class is created from another
derived class, then that inheritance is called as
multi level inheritance.
HYBRID INHERITANCE
• Any combination of single, hierarchical and
multi level inheritances is called as hybrid
inheritance.
MULTIPLE INHERITANCE
• when a derived class is created from more
than one base class then that inheritance is
called as multiple inheritance.
Single inheritance
<?php
class parentclass
{
public function sum($a,$b)
{
echo $a+$b;
}
}
class childclass extends parentclass
{
public function diff($a,$b)
{
echo $a-$b;
}
}
$obj1=new childclass();
$obj1->sum(4,5);
echo "<br />";
echo "<br />";
$obj1->diff(8,3);
?>
Output:
http://localhost/phpWorkspace/oops.php/inheritance1.php
Hierarchical inheritance
<?php
class a
{
public function function_a()
{
echo "classA";
}
}
class b extends a
{
public function function_b()
{
echo "classB";
}
}
class c extends a
{
public function function_c()
{
echo "classC";
}
}
echo c::function_c();
echo "<br />";
echo c::function_a();
echo “<br />
echo b::function_a();
?>
• Output
http://localhost/phpWorkspace/oops.php/hie
rarchicalinheritance.php
Multilevel inheritance
<?php
class a
{
public function function_a()
{
echo 'classa';
}
}
class b extends a
{
public function function_b()
{
echo 'classb';
}
}
class c extends b
{
public function function_c()
{
echo 'classc';
}
}
echo c::function_c();
echo "<br />";
eCho c::function_b();
echo "<br />";
echo c::function_a();
?>
OUTPUT
http://localhost/phpWorkspace/oops.php/multilevel.php
POLYMORPHISM
• Poly means many,morphism means forms.
• Polymorphism feature enables classes to
provide different implementation of methods
having the same name.
• Two types of polymorphism
Compile time(overloading)
Runtime(overriding)
OVERRIDING
• When we create a function in a derived class
with the same signature (in other words a
function has the same name, the same
number of arguments and the same type of
arguments) as a function in its parent class
then it is called method overriding.
example
<?php
class Shap
{
function draw(){}
}
class Circle extends Shap
{
function draw()
{
print "Circle has been drawn.</br>";
}
}
class Triangle extends Shap
{
function draw()
{
print "Triangle has been drawn.</br>";
}
}
class Ellipse extends Shap
{
function draw()
{
print "Ellipse has been drawn.";
}
}
}
$Val=array(2);
$Val[0]=new Circle();
$Val[1]=new Triangle();
$Val[2]=new Ellipse();
for($i=0;$i<3;$i++)
{
$Val[$i]->draw();
}
?>
• Output
http://localhost/phpWorkspace/oops.php/overriding.php
OVERLOADING
• Method overloading means having two or
more methods with the same name but
different signatures in the same scope. These
two methods may exist in the same class or
another one in base class and another in
derived class.
Example<?php
function findSum()
{
$sum = 0;
foreach (func_get_args() as $arg)
{
$sum += $arg;
}
return $sum;
}
echo findSum(1, 2), '<br />';
echo findSum(10, 2, 100), '<br />';
echo findSum(10, 22, 0.5, 0.75, 12.50), '<br />';
?>
Output:
http://localhost/phpWorkspace/oops.php/overloading.php
DATA ABSTRACTION
• Any representation of data in which the implementation
details are hidden (abstracted).
• Data abstraction refers to, providing only essential
information to the outside word and hiding their background
details ie. to represent the needed information in program
without presenting the details
• They provide sufficient public methods to the outside world
to play with the functionality of the object and to manipulate
object data ie. state without actually knowing how class has
been implemented internally.
ABSTRACT CLASS
• An abstract class is one that cannot be
instantiated, only inherited. You declare an
abstract class with the keyword abstract
• When inheriting from an abstract class, all
methods marked abstract in the parent's class
declaration must be defined by the child;
<?php
abstract class One
{
abstract function disp();
}
class Two extends One
{
public function disp()
{
echo "Inside the child class<br/>";
}
}
class Three extends One
{
public function disp()
{
echo "Inside the child class 2<br/>";}
}
$two=new Two();
echo "<b>Calling from the child class Two:</b><br/>";
$two->disp();
echo "<b>Calling from the child class Three:</b><br/>";
$three=new Three();
$three->disp();
?>
Output
http://localhost/phpWorkspace/oops.php/abstractclass.php
INTERFACE
• Interface is a special class used like a template
for a group of classes with similar functions,
which must define a certain structure of
methods.
• It can contain constants and method
declarations, but not method bodies.
<?php
interface testdrive
{
function drive();
function stop();
}
class vehicle implements testdrive
{
public function __construct()
{
echo 'About this Vehicle.<br />';
}
public function drive()
{
echo 'VRRROOOOOOM!!!';
}
public function stop()
{
echo 'SSSCCRRREEEEEECCHH!!!<br />';
}
}
$object = new vehicle;
$object->drive();
$object->stop();
?>
Output
http://localhost/phpWorkspace/oops.php/interf
ace.php
ABSTRACT CLASS INTERFACE
The Abstract methods can declare with
Access modifiers like public, internal,
protected. When implementing in
subclass these methods must be defined
with the same (or a less restricted)
visibility.
All methods declared in an interface must
be public.
Abstract class can contain variables and
concrete methods.
Interfaces cannot contain variables and
concrete methods except constants.
A class can Inherit only one Abstract class
and Multiple inheritance is not possible
for Abstract class.
A class can implement many interfaces
and Multiple interface inheritance is
possible.
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com

More Related Content

What's hot (20)

PPTX
Std 12 computer chapter 6 object oriented concepts (part 1)
Nuzhat Memon
 
PPTX
pointer-to-object-.pptx
ZaibunnisaMalik1
 
PPTX
Relational algebra (basics)
usama nizam
 
PPT
Chapter 02 php basic syntax
Dhani Ahmad
 
PPTX
Ppt on this and super keyword
tanu_jaswal
 
PDF
Object oriented approach in python programming
Srinivas Narasegouda
 
PPT
J2ee
Prince Soni
 
PPTX
Advance OOP concepts in Python
Sujith Kumar
 
PPTX
Object oriented programming concepts
rahuld115
 
PPTX
Destructors
DeepikaT13
 
PPT
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
PPTX
Java script
Abhishek Kesharwani
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PPT
2. Entity Relationship Model in DBMS
koolkampus
 
PPTX
Constructor and Destructor
Sunipa Bera
 
PDF
dot net unit-1.pdf
Prof. Dr. K. Adisesha
 
PPT
7.data types in c#
Zeeshan Ahmad
 
Std 12 computer chapter 6 object oriented concepts (part 1)
Nuzhat Memon
 
pointer-to-object-.pptx
ZaibunnisaMalik1
 
Relational algebra (basics)
usama nizam
 
Chapter 02 php basic syntax
Dhani Ahmad
 
Ppt on this and super keyword
tanu_jaswal
 
Object oriented approach in python programming
Srinivas Narasegouda
 
Advance OOP concepts in Python
Sujith Kumar
 
Object oriented programming concepts
rahuld115
 
Destructors
DeepikaT13
 
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Java script
Abhishek Kesharwani
 
Introduction to JavaScript
Andres Baravalle
 
2. Entity Relationship Model in DBMS
koolkampus
 
Constructor and Destructor
Sunipa Bera
 
dot net unit-1.pdf
Prof. Dr. K. Adisesha
 
7.data types in c#
Zeeshan Ahmad
 

Viewers also liked (20)

PDF
What's new in PHP 7.1
Simon Jones
 
PPT
Oops concepts in php
CPD INDIA
 
PPTX
Object Oriented Programming C#
Muhammad Younis
 
PPTX
Object oriented programming in php 5
Sayed Ahmed
 
PDF
Modern PHP
Simon Jones
 
PPTX
Introduction to PHP OOP
fakhrul hasan
 
ODP
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
ODP
Php variables (english)
Mahmoud Masih Tehrani
 
PPTX
Constructor and encapsulation in php
SHIVANI SONI
 
PPT
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
ODP
Htmltag.ppt
anandha ganesh
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PPS
Execute MySQL query using command prompt
Ikhwan Krisnadi
 
PPT
PHP
sometech
 
PPSX
PHP Comprehensive Overview
Mohamed Loey
 
ODP
Form Processing In Php
Harit Kothari
 
PPT
PHP variables
Siddique Ibrahim
 
PPTX
State management
Iblesoft
 
What's new in PHP 7.1
Simon Jones
 
Oops concepts in php
CPD INDIA
 
Object Oriented Programming C#
Muhammad Younis
 
Object oriented programming in php 5
Sayed Ahmed
 
Modern PHP
Simon Jones
 
Introduction to PHP OOP
fakhrul hasan
 
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
Php variables (english)
Mahmoud Masih Tehrani
 
Constructor and encapsulation in php
SHIVANI SONI
 
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
Htmltag.ppt
anandha ganesh
 
Arrays in PHP
Vineet Kumar Saini
 
Execute MySQL query using command prompt
Ikhwan Krisnadi
 
PHP Comprehensive Overview
Mohamed Loey
 
Form Processing In Php
Harit Kothari
 
PHP variables
Siddique Ibrahim
 
State management
Iblesoft
 
Ad

Similar to OOPS Characteristics (With Examples in PHP) (20)

PPTX
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
PPTX
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
PPTX
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
PDF
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
 
PDF
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 
PDF
Demystifying Object-Oriented Programming - Lone Star PHP
Alena Holligan
 
PPTX
Only oop
anitarooge
 
PPT
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
PDF
Demystifying Object-Oriented Programming #ssphp16
Alena Holligan
 
PDF
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
PPTX
Oo ps
seema chauhan
 
PDF
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
PPTX
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
PDF
Object_oriented_programming_OOP_with_PHP.pdf
GammingWorld2
 
PPTX
Intro To C++ - Class #22: Inheritance, Part 1
Blue Elephant Consulting
 
PPTX
Inheritance
Burhan Ahmed
 
PDF
OOP in PHP
Alena Holligan
 
PDF
PHP OOP
Oscar Merida
 
PPTX
Object oriented programming in php
Aashiq Kuchey
 
PDF
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
Bart Feenstra
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
UNIT III (8).pptx
DrDhivyaaCRAssistant
 
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
 
Demystifying Object-Oriented Programming - ZendCon 2016
Alena Holligan
 
Demystifying Object-Oriented Programming - Lone Star PHP
Alena Holligan
 
Only oop
anitarooge
 
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Demystifying Object-Oriented Programming #ssphp16
Alena Holligan
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Alena Holligan
 
Take the Plunge with OOP from #pnwphp
Alena Holligan
 
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
Object_oriented_programming_OOP_with_PHP.pdf
GammingWorld2
 
Intro To C++ - Class #22: Inheritance, Part 1
Blue Elephant Consulting
 
Inheritance
Burhan Ahmed
 
OOP in PHP
Alena Holligan
 
PHP OOP
Oscar Merida
 
Object oriented programming in php
Aashiq Kuchey
 
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
Bart Feenstra
 
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
PDF
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 

OOPS Characteristics (With Examples in PHP)

  • 2. OOPS CONCEPTS Rajishma T [email protected] www.facebook.com/ Rajishma T Nair twitter.com/username in.linkedin.com/in/profilename 9020217968
  • 3. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4. CLASS  A class is an expanded concept of a data,it can hold both data and functions. A class is the blueprint for your object. A class, for example, is like a blueprint for a house. It defines the shape of the house on paper, with relationships between the different parts of the house clearly defined and planned out, even though the house doesn’t exist.
  • 5. visibility The visibility of class members, (properties, methods), relates to how that member may be manipulated within, or from outside the class.  private:private members are accessible only in the class itself. Public:public members are accessible outside the class(anywhere). Protected:protected members are accessible in the same package,and the subclasses of the class and inside the class.
  • 6. OOPS CHARACTERESTICS  data encapsulation.  inheritance. Polymorphism. Data abstraction.
  • 7. ENCAPSULATION The wrapping up of a data and functions into a single unit(which is called class). Encapsulation means that some or all of an objects internal structure is hidden from the outside world. Hidden information may only be accessed through the object’s public interface.
  • 8. example <?php class MyClass { public $prop1 = "I'm a class property!"; public function setProperty($newval) { $this->prop1 = $newval; } public function getProperty() { return $this->prop1 . "<br />"; } } $obj = new MyClass; echo $obj->getProperty(); // Get the property value $obj->setProperty("I'm a new property value!"); // Set a new one echo $obj->getProperty(); // Read it out again to show the change ?> Output • http://localhost/phpWorkspace/oops.php/class.php
  • 9. INHERITANCE • When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class. • A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). • The class from which the subclass is derived is called a superclass (also a base class or a parent class).
  • 10. TYPES OF INHERITANCE • Single Inheritance • Hierarchical Inheritance • Multi Level Inheritance • Hybrid Inheritance • Multiple Inheritance
  • 11. SINGLE INHERITANCE • when a single derived class is created from a single base class then the inheritance is called as single inheritance.
  • 12. HIERARCHICAL INHERITANCE • when more than one derived class are created from a single base class, then that inheritance is called as hierarchical inheritance.
  • 13. MULTILEVEL INHERITANCE • when a derived class is created from another derived class, then that inheritance is called as multi level inheritance.
  • 14. HYBRID INHERITANCE • Any combination of single, hierarchical and multi level inheritances is called as hybrid inheritance.
  • 15. MULTIPLE INHERITANCE • when a derived class is created from more than one base class then that inheritance is called as multiple inheritance.
  • 16. Single inheritance <?php class parentclass { public function sum($a,$b) { echo $a+$b; } } class childclass extends parentclass { public function diff($a,$b) { echo $a-$b; } } $obj1=new childclass(); $obj1->sum(4,5); echo "<br />"; echo "<br />"; $obj1->diff(8,3); ?> Output: http://localhost/phpWorkspace/oops.php/inheritance1.php
  • 17. Hierarchical inheritance <?php class a { public function function_a() { echo "classA"; } } class b extends a { public function function_b() { echo "classB"; } } class c extends a { public function function_c() { echo "classC"; } }
  • 18. echo c::function_c(); echo "<br />"; echo c::function_a(); echo “<br /> echo b::function_a(); ?> • Output http://localhost/phpWorkspace/oops.php/hie rarchicalinheritance.php
  • 19. Multilevel inheritance <?php class a { public function function_a() { echo 'classa'; } } class b extends a { public function function_b() { echo 'classb'; } } class c extends b { public function function_c() { echo 'classc'; } }
  • 20. echo c::function_c(); echo "<br />"; eCho c::function_b(); echo "<br />"; echo c::function_a(); ?> OUTPUT http://localhost/phpWorkspace/oops.php/multilevel.php
  • 21. POLYMORPHISM • Poly means many,morphism means forms. • Polymorphism feature enables classes to provide different implementation of methods having the same name. • Two types of polymorphism Compile time(overloading) Runtime(overriding)
  • 22. OVERRIDING • When we create a function in a derived class with the same signature (in other words a function has the same name, the same number of arguments and the same type of arguments) as a function in its parent class then it is called method overriding.
  • 23. example <?php class Shap { function draw(){} } class Circle extends Shap { function draw() { print "Circle has been drawn.</br>"; } } class Triangle extends Shap { function draw() { print "Triangle has been drawn.</br>"; } } class Ellipse extends Shap { function draw() { print "Ellipse has been drawn."; } } }
  • 24. $Val=array(2); $Val[0]=new Circle(); $Val[1]=new Triangle(); $Val[2]=new Ellipse(); for($i=0;$i<3;$i++) { $Val[$i]->draw(); } ?> • Output http://localhost/phpWorkspace/oops.php/overriding.php
  • 25. OVERLOADING • Method overloading means having two or more methods with the same name but different signatures in the same scope. These two methods may exist in the same class or another one in base class and another in derived class.
  • 26. Example<?php function findSum() { $sum = 0; foreach (func_get_args() as $arg) { $sum += $arg; } return $sum; } echo findSum(1, 2), '<br />'; echo findSum(10, 2, 100), '<br />'; echo findSum(10, 22, 0.5, 0.75, 12.50), '<br />'; ?> Output: http://localhost/phpWorkspace/oops.php/overloading.php
  • 27. DATA ABSTRACTION • Any representation of data in which the implementation details are hidden (abstracted). • Data abstraction refers to, providing only essential information to the outside word and hiding their background details ie. to represent the needed information in program without presenting the details • They provide sufficient public methods to the outside world to play with the functionality of the object and to manipulate object data ie. state without actually knowing how class has been implemented internally.
  • 28. ABSTRACT CLASS • An abstract class is one that cannot be instantiated, only inherited. You declare an abstract class with the keyword abstract • When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child;
  • 29. <?php abstract class One { abstract function disp(); } class Two extends One { public function disp() { echo "Inside the child class<br/>"; } } class Three extends One { public function disp() { echo "Inside the child class 2<br/>";} }
  • 30. $two=new Two(); echo "<b>Calling from the child class Two:</b><br/>"; $two->disp(); echo "<b>Calling from the child class Three:</b><br/>"; $three=new Three(); $three->disp(); ?> Output http://localhost/phpWorkspace/oops.php/abstractclass.php
  • 31. INTERFACE • Interface is a special class used like a template for a group of classes with similar functions, which must define a certain structure of methods. • It can contain constants and method declarations, but not method bodies.
  • 32. <?php interface testdrive { function drive(); function stop(); } class vehicle implements testdrive { public function __construct() { echo 'About this Vehicle.<br />'; } public function drive() { echo 'VRRROOOOOOM!!!'; } public function stop() { echo 'SSSCCRRREEEEEECCHH!!!<br />'; } }
  • 33. $object = new vehicle; $object->drive(); $object->stop(); ?> Output http://localhost/phpWorkspace/oops.php/interf ace.php
  • 34. ABSTRACT CLASS INTERFACE The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility. All methods declared in an interface must be public. Abstract class can contain variables and concrete methods. Interfaces cannot contain variables and concrete methods except constants. A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class. A class can implement many interfaces and Multiple interface inheritance is possible.
  • 35. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 36. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com