如何从主方法调用非静态方法?

如何从主方法调用非静态方法?,第1张

如何从主方法调用静态方法?

你不能 非静态方法是必须在Test类的实例上调用的方法。创建Test的实例以在您的main方法中使用:

public class Test {    public static void main(String args[]) {        int[] arr = new int[5];        arr = new int[] { 1, 2, 3, 4, 5 };        Test test = new Test();        test.arrPrint(arr);    }    public void arrPrint(int[] arr) {        for (int i = 0; i < arr.length; i++) System.out.println(arr[i]);    }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5430370.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-11
下一篇2022-12-11

发表评论

登录后才能评论

评论列表(0条)

    保存