首页 > IT职业 > IT职场 > 在main方法中调用其他方法
要在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/ ,如需转载,请注明出处,否则将追究法律责任。