三分归元气,七分靠打拼 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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!