ITPub博客

首页 > IT职业 > IT职场 > 在main方法中调用其他方法

在main方法中调用其他方法

IT职场 作者:micromad 时间:2021-09-09 08:59:55 0 删除 编辑

要在main方法中调用print方法,首先要声明并实例化对象!因为类是抽象的

具体操作是 类名称(HelloWorld) 对象名称(test) HelloWorld test; //声明了

然后通过关键字new分配空间 test = new HelloWorld(); //分配空间了

合成一起就是 HelloWorld test = new HelloWorld(); //声明并实例化

最后调用方法的格式是:对象(test).方法(print) test.print

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2763/viewspace-2798436/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    75
  • 访问量
    574