public class Interval {        int start;
        int end;        Interval() {
            start = 0;
            end = 0;
        }        Interval(int s, int e) {
            start = s;
            end = e;
        }
    }
public static void main(String[] args) {
     Interval inte = new Interval(1,2);//这个会出错 请问怎么new一个呢
}

解决方案 »

  1.   

    你需要new一个外围类的对象,比如w
    Interval inte = w.new Interval(1,2);
    这样写就可以了
      

  2.   

    或者直接变为outer class
      

  3.   

    public class TestTop  {

      int start;
          int end;      TestTop() {
              start = 0;
              end = 0;
          }/* 默认构造器
         public TestTop() {
      // TODO Auto-generated constructor stub
      }
         */     TestTop(int s, int e) {//一般构造器使用public修饰.
              start = s;
              end = e;
         System.out.println("start="+s+"end="+end); 
         }
         
         
      //}这个大括号位置错了.
    public static void main(String []args) {
    // TODO Auto-generated method stu      TestTop inte = new TestTop(10,20);//这个会出错 请问怎么new一个呢
    }

    }//最后应该是有两个大括号才对.
      

  4.   

    1.构造函数变成public的
    2.通过反射来创建对象
      

  5.   

    子类 a=new 父类.子类();
      

  6.   

    package com;public class Problem_3 { public static void main(String[] args) {
    Interval inte = new Interval(1, 2);// 这个会出错 请问怎么new一个呢
    }
    }class Interval { int start;
    int end; Interval() {
    start = 0;
    end = 0;
    } Interval(int s, int e) {
    start = s;
    end = e;
    }
    }