错误找不到符号 - 变量

时间:2015-12-23 22:46:47

标签: java variables find symbols

我是使用Java的新手 - 所以请原谅我的无知。你能看到这段代码并告诉我为什么会收到错误:

  

找不到符号 - 变量

当我调用构造函数方法时。我正在使用BlueJ。基本上我放入变量然后点击确定创建一个对象,但它出现了错误。

/**
 * Write a description of class Membership here.
 * 
 * @author (Gohar Warraich) 
 * @version (1.0)
 */

public class Membership
{
    // instance variables - replace the example below with your own
    private String firstname;
    private String lastname;
    private String phonenumber;
    private int idnumber;

    /**
     * Constructor for objects of class Membership
     */
    public Membership(String newfirstname, String newlastname, String newphonenumber, int newidnumber)
    {
        // initialise instance variables
        firstname = newfirstname;
        lastname = newlastname;
        phonenumber = newphonenumber;
        idnumber = newidnumber;

    }

    /**
     * Accessor method of Membership
     */
    public String getfirstname()
    {
        return firstname;
    }

    public String getlastname()
    {
        return lastname;
    }

    public String getphonenumber()
    {
        return phonenumber; 
    }

    public int getidnumber()
    {
        return idnumber;
    }

    /**
     * Mutator method of Membership 
     */
    public void setfirstname(String insertfirstname)
    {
        firstname = insertfirstname;
    }

    public void setlastname(String insertlastname)
    {
        lastname = insertlastname;
    }

    public void setphonenumber(String insertphonenumber)
    {
        phonenumber = insertphonenumber;
    }

    public void setid(int insertidnumber)
    {
        idnumber = insertidnumber;
    }

    public void printMembership()
    {
        System.out.println("The firstname is " + firstname + " The lastname is " + lastname +" The phoneNumber is "+ phonenumber +" The idNumber is " +idnumber); 
    }
}

1 个答案:

答案 0 :(得分:0)

@gohar,此代码中没有问题。它必须在你对构造函数的调用中。我将举例说明这应该是什么样的。

Membership membershipName = new Membership ("String", "String", "String", 0101) 

0101可以是任何int,您可以通过更改membershipName来命名变量。希望这可以帮助。 :)