public class tesk{
public static void main(String args[])
{
Rectangl rr = new Rectangl(2,3);

System.out.println(rr.circumf());

System.out.println(rr.area());
}
    class Rectangl 
    {
    double length;
    double width;
Rectangl(double x,double y)
{
length=x;
width=y;
}
double  circumf()
{
return(2*(length+width));
}
double area()
{
return(length*width);
}
}

}
大神们哪里错了 啊   我是新手啊 

解决方案 »

  1.   

    你用的是内部类,如果实例化内部类,就得先实例化外部类public class Demo5 {
    public static void main(String args[]) {
    Rectangl rr = new Demo5().new Rectangl(2, 3);
    System.out.println(rr.circumf());
    System.out.println(rr.area());
    } class Rectangl {
    double length;
    double width; Rectangl(double x, double y) {
    length = x;
    width = y;
    } double circumf() {
    return (2 * (length + width));
    } double area() {
    return (length * width);
    }
    }
    }
      

  2.   

    注意这句:Rectangl rr = new Demo5().new Rectangl(2, 3);
      

  3.   

    静态内部类也行class Rectangl  ------------>static class Rectangl  
    就可以了
      

  4.   

    public class tesk
    {
    public static void main(String args[])
    {
    Rectangl rr = new tesk().new Rectangl(2,3);System.out.println(rr.circumf());System.out.println(rr.area());
    }
      
      class Rectangl 
      {
       double length;
      double width;
      
    Rectangl(double x,double y)
    {
    length=x;
    width=y;
    }double circumf()
    {
    return(2*(length+width));
    }
    double area()
    {
    return(length*width);
    }
    }}
    你这两个类构成的结构是:
    public class tesk
    {
    ...
    class Rectangl   
    {
    ....
    }
    }
    这属于内部类的形式:
    实现内部类的实例化时:格式是:
    OuterClass.InnerClass innerObject = new OuterClass.newInnerClass();
      

  5.   

    static class Rectangl {}
    内部类改成静态的也行