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);
}
}
}
大神们哪里错了 啊 我是新手啊
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);
}
}
}
大神们哪里错了 啊 我是新手啊
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);
}
}
}
就可以了
{
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();
内部类改成静态的也行