it seems you are a java beginner. anyway, the main errors are:
1) if you want to assign the arguments of your constructor to the objects fields, the argument names must match the one given in the method. ex.
public Phone(String firstname1, String lastname1, String number1)
{
firstname = firstname1;
2) If you use a constructor to initialize the field variables you don't need any setter methods and you methods doesn't need to be static.
3) The method signature doesn't end with a semicolon. so
public void setfirstname(String first1);
{
will not run, but
public void setfirstname(String first1)
{
is ok.
4) Java is case sensitive, so an identifier getLastName will not be recognized by the compiler if you use getlastname.
5) If you make a call to a method you must specify the object or if the method is static you must specify the class. only getfirstname() will not work.
Here is the code that will compile and run:
Code:
public class Phone {
private String firstname;
private String lastname;
private String number;
public Phone() {
}
public Phone(String firstname1, String lastname1, String number1) {
firstname = firstname1;
lastname = lastname1;
number = number1;
}
public String getfirstname() {
return firstname;
}
public String getlastname() {
return lastname;
}
public String getnumber() {
return number;
}
public static void main(String[] args) {
Phone p1 = new Phone("Albert", "Einstein", "01-11111");
System.out.println("First Name : " + p1.getfirstname());
System.out.println("Last Name : " + p1.getlastname());
System.out.println("Number : " + p1.getnumber());
}
}
and the output will be:
Quote:
First Name : Albert
Last Name : Einstein
Number : 01-11111
|