方法的调用

  • 静态方法

  • 非静态方法

  • public class Day02 {
        public static void main(String[] args) {
            //Student.say();静态方法  static
            Student student = new Student();
            //非静态方法  没有加 static 实例化这个类 new
           //对象类型 对象名字=对象的值
            student.say();
        }
        //static是 和类一起加载的
        public void a(){
          b();//两个都是static方法也可以调用
        }
        public void b(){
         //类实例化以后才存在的
        }
    }
  • 形叁和实叁

  • {
        public static void main(String[] args) {
            //实际参数和形式参数的类型要对应
            int add = Day03.add(1, 2);
            System.out.println(add);
        }
        public static int add(int a,int b){
            return a+b;
        }
    }
  • 值传递和引用传递

  • //值传递
    public class Day04 {
        public static void main(String[] args) {
            int a =1;
            System.out.println(a);//1
            Day04.change(a);
            System.out.println(a);//1
    ​
        }
        //返回值为空
        public static void change(int a){
            a =10;
    ​
        }
    }
    package com.xiaoming.oop.OOP;
    //引用传递  对象本质还是值传递
    public class Day05 {
        //对象  内存  
        public static void main(String[] args) {
            Perosn perosn = new Perosn();
            System.out.println(perosn.name);
           Day05.change(perosn);
            System.out.println(perosn.name);
        }
        public static void change(Perosn perosn){
            // perosn是一个对象 他指向的--->Perosn perosn = new Perosn();这是一个具体的人可以改变属性
            perosn.name = "小明";
        }
    }
    //定义了一个Perosn类 有一个属性name
      class Perosn{
            String name;
            }
  • this关键字

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值