回顾方法
- 方法的定义
- 修饰符
- 返回类型
- break和return的区别:break跳出switch,结束循环;return结束
- 方法名:注意规范,见名知意
- 参数列表:(参数类型,参数名)…
- 异常抛出
package com.oop;
import java.io.IOException;
public class Demo01 {
public static void main(String[] args) {
}
public String sayHello(){
return "hello,world";
}
public void sayHello1(){
return;
}
public int max(int a,int b){
return a>b?a:b;
}
public void readFile(String file)throws IOException{
}
}
- 方法的调用
- 静态方法
- 非静态方法
- 形参和实参
- 值传递和引用传递
- this关键字 --继承和多态再讲
package com.oop.demo01;
public class Demo05 {
public static void main(String[] args) {
Person person = new Person();
System.out.println(person);
System.out.println(person.name);
Demo05.change(person);
System.out.println(person.name);
}
public static void change(Person person){
person.name = "ty";
}
}
class Person{
String name;
}