Java - 圆柱程序 - 无法使用main

rks*_*stm 1 java methods static-methods compiler-errors

我迷路了,我甚至不知道要问什么问题.我有这个程序,应该能够构造一个参数半径和高度的圆柱体.然后它应该能够调用各种方法来获取和设置半径以及输出表面积和体积.我无法通过去因为我不能在我的主要内容中放置任何内容而没有关于静态中使用的静态非静态方法的错误.我甚至都不知道这意味着什么.我实际上将其他人的代码复制到我的编译器中,它给了我同样的错误.我搞砸了一些设置吗?我知道这对Stack Overflow来说可能太过初级,但我现在绝望了.

public class Miller_A03Q1 {

    public static void main(String[] args) {
        Cylinder cylinder1 = new Cylinder(1,17);
        Cylinder cylinder2 = new Cylinder(3,8);
        Cylinder cylinder3 = new Cylinder(2,12);
        Cylinder cylinder4 = new Cylinder (1,14);    
    }

    public class Cylinder{
        private double radius = 0.0;
        private double height= 0.0;
        private double area = 0.0;
        private double volume=0.0;
        private String shape = "cylinder";


        public Cylinder(double r,double h){
            this.radius = r;
            System.out.print(r);
            this.height = h;
            System.out.print(h);

        }
        public double getVolume(){
            double volume = 3.14 * radius * radius * height;
            return volume;
        }
        public double getArea(){
            double circumference = 3.14 * 2 * radius;
            double circleArea = 3.14 * radius * radius;
            double area = (2 * circleArea) + (circumference * this.height);
            return area;
        }
        public double getRadius(){
            return this.radius;
        }
        public double getHeight(){
            return this.height;
        }
        public void setHeight(double h){
            this.height = h;
        }
        public void setRadius(double r){
            this.radius = r;
        }
        @Override
        public String toString(){
            return this.shape + this.radius + this.height+ this.volume + this.area;
        }            
    }       
} 
Run Code Online (Sandbox Code Playgroud)

Mur*_*nik 5

内部类与任何其他成员一样(嗯,除了enums).如果您没有明确声明它们static,它们将不会,因此您将无法从静态上下文访问它们,例如main.长话短说 - 宣称你是Cylinder内部阶级static,你应该没问题:

public class Miller_A03Q1 {

    public static void main(String[] args) {
        Cylinder cylinder1 = new Cylinder(1,17);
        Cylinder cylinder2 = new Cylinder(3,8);
        Cylinder cylinder3 = new Cylinder(2,12);
        Cylinder cylinder4 = new Cylinder (1,14);
    }

    public static class Cylinder{
        // etc...
Run Code Online (Sandbox Code Playgroud)