三分归元气,七分靠打拼 2015-05-11 13:20 采纳率: 33.3%
浏览 1446
已采纳

两个类,实例化问题,实例化报错

public class Paixu {

public static void main(String[] args) {

    //   Paixu px=new Paixu();

    MaoPaoSort mp=new MaoPaoSort();

//上面这里就开始报错了:No enclosing instance of type Paixu is accessible. Must qualify the allocation with an enclosing instance of type Paixu (e.g. x.new A() where x is an instance of Paixu).
}

class MaoPaoSort {
    public  void test1() {
        int a[] = { 1, 1234, 356, 123, 56346, 73, 45342342, 1, 3, 56, };

        for (int i = 0; i < a.length; i++) {

            for (int j = i + 1; j < i - 1; j++) {
                if (a[i] < a[j]) {
                    int tmp = a[i];
                    a[i] = a[j];
                    a[j] = tmp;
                    System.out.println(a[j]);
                }
            }
        }

    }


}

}

  • 写回答

7条回答

  • bdmh 移动开发领域优质创作者 2015-05-11 13:36
    关注

    不能在静态函数中new,把 MaoPaoSort改成静态的类

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调