靜態方法static 的瞭解

學習了static靜態方法,靜態變量的一些知識,簡單的進行一些總結:學習

  1. 靜態方法無參數且無返回值的方法spa

  2. 靜態方法有參數無返回值的方法input

  3. 靜態方法有返回值的方法it


  1. 靜態方法中無返回值的定義在void,使用void定義的方法都不帶返回值,且方法名後()內不帶參數變量

  

 static void input(){                                           //定義一個input方法不帶返回值,不帶參數引用

  Scanner scanner= new Scanner(System.in);方法

System.out.print("姓名:");總結

name=scanner.next(); next

    System.out.print("性別:");static

sex=scanner.next().charAt(0);

System.out.println("年齡:");

age=scanner.nextShort();

System.out.println("身高");

height=scanner.nextFloat();

    System.out.println("性格:");

type=scanner.next(); 

  

   }

2

  1. 靜態方法中無返回值的定義在void,使用void定義的方法都不帶返回值,且方法名後()內帶參數

private static void feeling(String cause , String content) {      //使用參數,有兩個參數,表明兩種的狀態

System.out.println(cause);

System.out.println(content);


                     feeling(「心情不錯」,「中了500萬的緣故」)  //在別的方法內進行引用


3帶參數和返回值的方法,簡單的例子在於計算類型,輸入2個數字,計算結果的方法

   static   int math(int a,int b){

                return   

}

先簡單的作個記錄

相關文章
相關標籤/搜索