【问题标题】:can't find the error找不到错误
【发布时间】:2014-10-02 02:29:22
【问题描述】:

我在 main 中有错误,谁能帮我找到错误所在?我正在尝试创建一个类并使用 setter/getter 来设置每个字段,最终我将测试这个类以确保这些字段正常工作

public class College{

    public class person{

        private String name;
        private int age;
        private double id; 
        //constructor to set fields 
        public Schedule (String name, int age, double id){
             this.name= name;
             this.age= age;
             this.id= id;
        }

        public String getName(){
            return this.name;
        }

        public void setName(String Name) {
            this.name= name;
        }
        public int getAge(){
            return  this.Age;
        }

        public void setAge(int age) {
            this.age = age;
        }
        public double getId(){
            return this.id;
        }

        public void setId(double id) {
            this.id = id;
        }


    }

    public static void main(String[] args) {


        Schedule Per1= new College("John", 2,2.0);



    }


}

【问题讨论】:

  • 您需要在 main 中显示您尝试实例化/操作类的代码。

标签: class field


【解决方案1】:

我认为您可能想了解如何正确创建类。 下面的链接会帮助你(在 C# 中):

http://msdn.microsoft.com/en-us/library/x9afc042.aspx

public class person{

    private String name;
    private int age;
    private double id; 
    //constructor to set fields 
    public person(String name, int age, double id){
         this.name= name;
         this.age= age;
         this.id= id;
    }

    public String getName(){
        return this.name;
    }

    public void setName(String Name) {
        this.name= name;
    }
    public int getAge(){
        return  this.Age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public double getId(){
        return this.id;
    }

    public void setId(double id) {
        this.id = id;
    }


}

public static void main(String[] args) {


    person Per1= new person("John", 2,2.0);



}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 2012-12-29
    • 2013-11-24
    • 2011-09-20
    • 2017-09-21
    • 2015-02-08
    相关资源
    最近更新 更多