-
静态方法
-
非静态方法
-
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关键字