小编Dan*_*iel的帖子

通过第二和第三类更改类变量

我正在做一个个人项目,同时试验它.我在3个文件中包含3个类:Calculate.java,Geometry.java和Test.java.

到目前为止,Geometry.java只包含一些我想要使用的变量,get/set方法以及构造函数方法.

package project;  
public class Geometry {  
    public static double length, width;  
    public Geometry() {  
        this.setLength(20);  
        this.setWidth(30);  
    }  
    public void setLength(double length){  
        this.length = length;  
    }  
    public void setWidth(double width){  
        this.width = width;  
    }  
    public double getLength(){  
        return this.length;  
    }  
    public double getWidth(){  
        return this.width;  
    }  
}
Run Code Online (Sandbox Code Playgroud)

Calculate.java有一个Geometry类型的公共变量,以及一个处理我在Geometry.java中创建的变量的方法.

package project;  
import project.Geometry;  
public class Calculate {  
    public static Geometry figure = new Geometry();  
    public static double area;  
    public void calcArea(){  
        this.area = figure.getLength() * figure.getWidth();  
    }  
    public double getArea(){ …
Run Code Online (Sandbox Code Playgroud)

java variables class

1
推荐指数
1
解决办法
194
查看次数

标签 统计

class ×1

java ×1

variables ×1