java 提示cannot be resolved to a variable怎么解决 5
packagelin1;abstractclassshape{doublex;doubley;publicabstractvoidarea();}interfacezho...
package lin1;
abstract class shape{
double x;
double y;
public abstract void area();
}
interface zhouChang{
void ZChang();
}
class Xing extends shape implements zhouChang{
public double height;
public double width;
public Xing(double x,double y,double h,double w){
this.x=x;this.y=y;this.height=h;this.width=w;
}
public void area(){
System.out.println("长方形面积:"+width*height);
}
public void zChang(){
System.out.println("长方形周长:"+2*(width+height));
}
}
public class chang {
public static void main(String[] args) {
// TODO Auto-generated method stub
shape s;
Xing r;
Xing r1=new Xing(5.0,15.0,6.0,5.0);
shape r2=new Xing(10.0,10.0,8.0,9.0);
zhouChang r3=new Xing(15.0,15.0,4.0,8.0);
System.out.println("长方形r1的数据++++");
System.out.println("X,Y坐标:"+r1.x+","+r1.y);
System.out.println("宽|高:"+r1.width+","+r1.height);
r1.area();
r1.zChang();
if(r2 instanceof Xing)
System.out.println("r2是xing的数据");
System.out.println("长方形r2的数据++++");
System.out.println("X,Y坐标:"+r2.x+","+r2.y);
r=(Xing)*r2;
System.out.println("宽|高:"+r.width+","+r.height);
r2.area();
r.zChang();
if(r3 instanceof Xing)
System.out.println("r3是xing的数据");
System.out.println("长方形r3的数据++++");
s=(Xing)*r3;
System.out.println("X,Y坐标:"+s.x+","+s.y);
r=(Xing)*r3;
System.out.println("宽|高:"+r.width+","+r.height);
s.area();
r.zChang();}}
当程序中出现出多个class时,除了main的class,前面的class总是提示有错误,这是为什么 展开
abstract class shape{
double x;
double y;
public abstract void area();
}
interface zhouChang{
void ZChang();
}
class Xing extends shape implements zhouChang{
public double height;
public double width;
public Xing(double x,double y,double h,double w){
this.x=x;this.y=y;this.height=h;this.width=w;
}
public void area(){
System.out.println("长方形面积:"+width*height);
}
public void zChang(){
System.out.println("长方形周长:"+2*(width+height));
}
}
public class chang {
public static void main(String[] args) {
// TODO Auto-generated method stub
shape s;
Xing r;
Xing r1=new Xing(5.0,15.0,6.0,5.0);
shape r2=new Xing(10.0,10.0,8.0,9.0);
zhouChang r3=new Xing(15.0,15.0,4.0,8.0);
System.out.println("长方形r1的数据++++");
System.out.println("X,Y坐标:"+r1.x+","+r1.y);
System.out.println("宽|高:"+r1.width+","+r1.height);
r1.area();
r1.zChang();
if(r2 instanceof Xing)
System.out.println("r2是xing的数据");
System.out.println("长方形r2的数据++++");
System.out.println("X,Y坐标:"+r2.x+","+r2.y);
r=(Xing)*r2;
System.out.println("宽|高:"+r.width+","+r.height);
r2.area();
r.zChang();
if(r3 instanceof Xing)
System.out.println("r3是xing的数据");
System.out.println("长方形r3的数据++++");
s=(Xing)*r3;
System.out.println("X,Y坐标:"+s.x+","+s.y);
r=(Xing)*r3;
System.out.println("宽|高:"+r.width+","+r.height);
s.area();
r.zChang();}}
当程序中出现出多个class时,除了main的class,前面的class总是提示有错误,这是为什么 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询