1. 程式人生 > 遊戲 >PS3售後將於4月30日結束 資深業者回顧PS3感動歷程

PS3售後將於4月30日結束 資深業者回顧PS3感動歷程

例子:

 1 public class Student {
 2     public static void main(String[] args) {
 3         Student student = new Student();
 4 
 5         //類變數,只有靜態變數才可以使用
 6         System.out.println(Student.age);
 7 
 8         //不用new一個物件在呼叫,因為方法是靜態的
 9         Student.go();
10 
11         //非靜態的必須先new,之後在呼叫
12         Student student1 = new
Student(); 13 student1.run(); 14 } 15 //靜態的變數 16 private static int age; 17 //非靜態的變數 18 private double score; 19 20 public void run(){ 21 //非靜態方法可以隨便呼叫靜態方法 22 go(); 23 } 24 public static void go(){ 25 26 } 27 }

例子:

 1 public class Person {
2 //2、 3 //可以付一些初始值 4 { 5 System.out.println("匿名程式碼塊"); 6 } 7 8 //方便初始化一些東西 9 //只執行一次 10 //1、 11 static{ 12 System.out.println("靜態程式碼塊!"); 13 } 14 15 //3、 16 public Person(){ 17 System.out.println("構造方法!"); 18 } 19 20 public static
void main(String[] args) { 21 System.out.println("========================"); 22 Person person = new Person(); 23 } 24 } 25 //final是常量修飾符,如果父類被final修飾了,就不能有子類繼承了

例子:

1 //靜態包
2 import static java.lang.Math.random;
3 public class Test {
4     public static void main(String[] args) {
5         //為了不寫Math匯入包
6         //System.out.println(Math.random());
7         System.out.println(random());
8     }
9 }