polymorphism is 1 name and many form. we us one think at many place or we can say that we use 1 single name object in many time. it is a oops concept also and it have ability to make many form of a single function.
It is two type,
In function overriding we have same name of function as well as same signature of the function in different class. for example we have 2 class , 1 is super and 2nd is sub class.one function have in super class with any parameter or without parameter.and same name and parameter also present in subclass. and we make inherit the super class by sab class then subclass override the function of base class.
program example of overriding in php is:-
<?php
class college
{
public function collegename()
{
echo"college name is IET</br>";
}
public function collegename2($name)
{
echo "college name is $name";
}
}
class subcollege extends college
{
public function collegename()
{
echo "college name is AIET</br>";
}
public function collegename2($name)
{
echo "college name is $name";
}
}
$c1 = new subcollege();
$c1-> collegename();
$c1->collegename2(NIT);
?>
if we try. overloading in php then it will give a error. example is below
<?php
class college
{
function department()
{
echo "this is b.tech department";
}
function department("$name")
{
echo"this is". $name." department";
}
}
$c1 = new college();
$c1->department();
$c1->department("iet");
?>
It is two type,
- Function overloading
- Function overriding
In function overriding we have same name of function as well as same signature of the function in different class. for example we have 2 class , 1 is super and 2nd is sub class.one function have in super class with any parameter or without parameter.and same name and parameter also present in subclass. and we make inherit the super class by sab class then subclass override the function of base class.
program example of overriding in php is:-
<?php
class college
{
public function collegename()
{
echo"college name is IET</br>";
}
public function collegename2($name)
{
echo "college name is $name";
}
}
class subcollege extends college
{
public function collegename()
{
echo "college name is AIET</br>";
}
public function collegename2($name)
{
echo "college name is $name";
}
}
$c1 = new subcollege();
$c1-> collegename();
$c1->collegename2(NIT);
?>
if we try. overloading in php then it will give a error. example is below
<?php
class college
{
function department()
{
echo "this is b.tech department";
}
function department("$name")
{
echo"this is". $name." department";
}
}
$c1 = new college();
$c1->department();
$c1->department("iet");
?>
No comments:
Post a Comment