<?php
interface a
{
public function foo();
}
interface b
{
public function bar();
}
interface c extends a, b
{
public function baz();
}
class d implements c
{
public function foo()
{
}
public function bar()
{
}
public function baz()
{
}
}
?>
<?php
trait ezcReflectionReturnInfo {
function getReturnType() { /*1*/ }
function getReturnDescription() { /*2*/ }
}
class ezcReflectionMethod extends ReflectionMethod {
use ezcReflectionReturnInfo;
/* ... */
}
class ezcReflectionFunction extends ReflectionFunction {
use ezcReflectionReturnInfo;
/* ... */
}
?>
abstract class Employee{
abstract void continueToWork();
}
class Sales extends Employee{
private void makeSalePlan(){
System.out.println("make sale plan");
}
public void continueToWork(){
makeSalePlan();
}
}
class Market extends Employee{
private void makeProductPrice(){
System.out.println("make product price");
}
public void continueToWork(){
makeProductPrice();
}
}
class Engineer extends Employee{
private void makeNewProduct(){
System.out.println("make new product");
}
public void continueToWork(){
makeNewProduct();
}
}
class Demo{
public static void main(String[] args){
Sales s = new Sales();
s.continueToWork();
Market m = new Market();
m.continueToWork();
Engineer e = new Engineer();
e.continueToWork();
}
}
class Demo{
public static void main(String[] args){
Work(new Sales());//Employee e = new Sales();
Work(new Market());//Employee e = new Market();
Work(new Engineer());//Employee e = new Engineer();
}
public static void Work(Employee e){
e.continueToWork();
}
}
class Demo{
public static void main(String[] args){
Work(new Sales());
Work(new Market());
Work(new Engineer());
}
public static void Work(Sales s){
s.continueToWork();
}
public static void Work(Market m){
m.continueToWork();
}
public static void Work(Engineer e){
e.continueToWork();
}
}
<?php
abstract class Employee{
abstract function continueToWork();
}
class Sales extends Employee{
private function makeSalePlan(){
echo "make sale plan";
}
public function continueToWork(){
$this->makeSalePlan();
}
}
class Market extends Employee{
private function makeProductPrice(){
echo "make product price";
}
public function continueToWork(){
$this->makeProductPrice();
}
}
class Engineer extends Employee{
private function makeNewProduct(){
echo "make new product";
}
public function continueToWork(){
$this->makeNewProduct();
}
}
class Demo{
public function Work(Employee $employeeObj){//添加父类类型限制传参类型,使其满足多态第三点要求,父类指向子类
$employeeObj->continueToWork();
}
}
//调用
$obj = new Demo();
$obj->Work(new Sales());
$obj->Work(new Market());
$obj->Work(new Engineer());
?>