梦入琼楼寒有月,行过石树冻无烟

JAVA 方法

什么是方法?

Java方法就是所有语句的集合,他们在一起执行一个功能能.比如下方:

System.out.println()

系统类.标准输出对象.输出方法()

静态调用

1
2
public static void one() {
}

​ 实例

1
2
3
4
5
6
7
8
9
10
public class Demo {
public static void one() {
System.out.println("one");
}
// 调用One 方法
public static void main (String args[]) {
Demo demo = Demo();
demo.one();
}
}

寻常方法

1
2
public void two () {
}

​ 实例

1
2
3
4
5
6
7
8
9
public class Demo {
public void Two() {
System.out.println("Two");
}
public static void main (String args[]) {
Demo demo = Demo();
demo.Two();
}
}
⬅️ Go back