/*
修饰符 返回值类型 方法名(...){
//方法体
return 返回值;
}
*/
public String test(){
return "hello";
}
public void test1(){
return;
}
public int max(int a,int b){
int c = a>b?1:0;
return c;
}
public class Demo02 {
public static void main(String[] args) {
Student.say();
}
}
public class Student {
// 静态方法:static
public static void say(){
System.out.println("student is saying");
}
}
//student is saying
public class Demo02 {
public static void main(String[] args) {
//实例化这个类
Student student = new Student();
student.say();
}
}
public class Student {
// 非静态方法
public void say(){
System.out.println("student is saying");
}
}
//student is saying
public static void main(String[] args) {
int a = 1;
change(a);
System.out.println(a);
}
//无返回值
public static void change(int a){
a = 10;
}
//1
public class Demo04 {
//引用传递:对象,本质还是值传递
public static void main(String[] args) {
Person person = new Person();
System.out.println(person.name);
Demo04.change(person);
System.out.println(person.name);
}
public static void change(Person person){
person.name = "张三";
}
}
//定义一个Person类,属性name
class Person{
String name;
}
//null
张三
原文:https://www.cnblogs.com/saxonsong/p/14633148.html