• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

HSpringX

大学生入门笔记
  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

方法的调用(类方法和成员方法)

public class Test1 {
    public static void main(String[] args) {
        int show = show();//直接调用
        System.out.println("类方法:"+show);
int add = Student.add(11, 12);//类名.调用 System.out.println("非本类的类方法:"+add);
int multiply = new Student().multiply(1, 4);//实例化对象调用 System.out.println("非本类的成员方法:"+multiply); Test1 t1=new Test1();//实例化对象调用 System.out.println("subtract方法:"+t1.subtract(22,4)); } public static int show(){ int a=2; return a; } public int subtract(int a, int b){ return a-b; } } class Student{ public static int add(int a,int b){ return a+b; } public int multiply(int a,int b){ return a*b; } }

 

posted on 2021-12-25 15:03  HSpringX  阅读(133)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3