回顾

回顾方法

  • 方法的定义

  • 修饰符

  • 返回类型

  • brak和return的区别

  • 方法名

  • 参数列表

  • 异常抛出

方法的调用

  • 静态方法

  • 非静态方法

  • 形参和实参

  • 值传递和引用传递

  • this关键字

package Dome01;
//Dome01 类
public class Dome01 {
    //main方法
  public static void main(String[] args) {
      System.out.println(hello());



  }
  /*
  修饰符   返回值 方法名字(.....){
  //方法体
  return 返回值;

  }
    */

      public static String hello (){
          return "hello";
      }

      public void a(){
          return;//return结束方法,返回一个结果。
      }

      public int max(int a,int b){
          return a>b? a : b;//三元运算符,这句话的意思是 如果a大于b那么就输出a,否则就输出b
      }
      //数组下标越界异常:Arrayindexootofbounds

}
package Dome01;

public class Dome02 {
  public static void main(String[] args)
  {
      //实例化这个类 new
      //对象类型 对象名 = 对象值;
      //静态方法,加上static
      //非静态方法,不加 static
      Student student = new Student();
      student.say();

  }


  public static void a(){
      b();

  }
  public static void b(){

  }
}
package Dome01;

public class Dome03 {
  public static void main(String[] args) {
      //实际参数,和形式参数的方法名要对立
      int add = Dome03.add(1, 2);
      System.out.println(add);
  }
  public static int add(int a, int b){
      return a+b;

  }
}
package Dome01;

public class Dome04 {
  public static void main(String[] args) {
      int a =1;
      System.out.println(a);
      Dome04.ch(a);
      System.out.println(a);
  }
  public static void ch(int a){
      a=10;
  }
}
package Dome01;
//引用传递:对象 ,本质还是值传递
//内存

public class Dome05 {
  public static void main(String[] args) {
      Perosn perosn = new Perosn();
      System.out.println(perosn.name);//null
      Dome05.ch(perosn);
      System.out.println(perosn.name);//王刚

  }
  public static void ch(Perosn perosn){
      //person是一个对象,指向的——>Perosn perosn = new Perosn();这是一个具体的人可以改变属性。
      perosn.name="王刚";

  }
   
}
//定义了一个Perosn类,有一个熟悉:name
class Perosn{
  String name;
}

 

posted @ 2021-07-12 16:11  πππ·  阅读(57)  评论(0)    收藏  举报