今天看到這篇文章PHP is not Java,覺得Satya還滿無辜的,不過~也藉此瞭解到Java與PHP的constructor有什麼不一樣。
- PHP
Result:PHP
<?php
class Person{
public function __construct(){
echo "I'm a person.\n";
}
}
class Man extends Person{
public function __construct(){
//parent::__construct();
echo "I'm a man.\n";
}
}
$i = new Man;
?> - Java
Result:Java
class Person{
public Person(){
System.out.println("I'm a person.");
}
}
class Man extends Person{
public Man(){
System.out.println("I'm a man.");
}
}
public class Main{
public static void main(String[] args){
Man i = new Man();
}
}
沒有留言:
張貼留言