Java教程

【无标题】

本文主要是介绍【无标题】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 1 class Person
 2 {
 3     const HOST = 'localhost';
 4 
 5     public function say(){
 6         echo 'hello';
 7     }
 8 }
 9 
10 echo Person::HOST;

复制代码

1 final class Person

2 {
3     const HOST = 'localhost';
4 
5     public function say(){
6         echo 'hello';
7     }
8 }

复制代码

复制代码

1 class Person
2 {
3     const HOST = 'localhost';
4 
5     final public function say(){
6         echo 'hello';
7     }
8 }

复制代码

  1.  1 class Person
     2 {
     3     public $name;
     4     static public $num;
     5 
     6     public function __construct($n){
     7         $this->name = $n;
     8         Person::$num++;
     9     }
    10 }
    11 new Person('user1');
    12 new Person('user2');
    13 new Person('user3');
    14 
    15 echo Person::$num; # 3

    复制代码

    复制代码

     1 # 
     2 
     3 class Person
     4 {
     5     public $name;
     6 
     7     public function __construct($n){
     8         $this->name = $n;
     9     }
    10 
    11     public function say(){
    12         echo "<p>my name is {$this->name}</p>";
    13     }
    14 
    15     static public function sum($i,$j){
    16         return $i+$j;
    17     }
    18 }
    19 
    20 echo Person::sum(5,25);

    复制代码

这篇关于【无标题】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!