类中的方法—-》做一件事情 []括起来的部分可以没有

权限修饰符 [特征修饰符] 返回值类型 方法名字 (参数列表) [抛出的异常] [
{ 方法体 }
]

无参数无返回值

  1. public class Index{
  2. public void test(){
  3. }
  4. }

无参数有返回值

  1. public class Index{
  2. public String test(){
  3. return "返回值"
  4. }
  5. }

有参数无返回值

  1. public class Index{
  2. // 参数可以有多个
  3. public void test(String type, int count){
  4. System.out.print(type);
  5. System.out.print(count);
  6. }
  7. }

有参数有返回值

  1. public class Index{
  2. public String test(String type){
  3. return type;
  4. }
  5. }