File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Fun with Constructors, etc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Fun with Constructors, etc" Watch "Fun with Constructors, etc" New topic
Author

Fun with Constructors, etc

Elaine Banks
Greenhorn

Joined: Dec 16, 2003
Posts: 18
Happy Holidays, All!
Okay - what am I doing wrong here:
I have two classes, Employee1 and EmployeeMaker:
======================================================
public class Employee1
{
private String firstName;
private String lastName;
private int empID;
private float salary;
//get and set for firstName
public String getFirstName ()
{
return firstName;
}
public void setFirstName (String firstNameIn)
{
firstName = firstNameIn;
}

//get and set for lastName
public String getLastName ()
{
return lastName;
}
public void setLastName (String lastNameIn)
{
lastName = lastNameIn;
}
//get and set for empID
public int getEmpID ()
{
return empID;
}
public void setEmpID (int empIDIn)
{
empID = empIDIn;
}
// get and set for salary
public float getHourlyWage ()
{
return salary;
}
public void setSalary (float wageIn)
{
salary = wageIn;
}
public Employee1 ()
{
firstName = "Unknown";
lastName = "Unknown";
empID = 0;
salary = 0.00f;
}
public Employee1 (String firstNameIn, String lastNameIn, int empIDIn, float salaryIn)
{
firstName = firstNameIn;
lastName = lastNameIn;
empID = empIDIn;
salary = salaryIn;
}
} //end of class
========================================================
public class EmployeeMaker
{
Employee1 employee101 = new Employee1 ("Kim", "Yee", 101, 40000.00f);
Employee1 employee102 = new Employee1 ("John", "Reynolds", 102, 55000.00f);
Employee1 employee103 = new Employee1 ("Elena", "Gonzales", 103, 50500.00f);
Employee1 employee104 = new Employee1 ("Jim", "OShea", 104, 75000.00f);
System.out.println (employee101.getLastName());
}
===========================================================
Why will that last line not compile? What's wrong with
System.out.println (employee101.getLastName());
???
Someone enlighten me please!
EB
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
I'm not sure; on the surface, it looks like it should work. What, exactly, is the error message you are getting, and is your code the same as what is posted here? (Sometimes you make a typo in your code that you don't make when posting code here -- that's why I recommend cutting-and-pasting code, and remember to put it between [CODE] and [/CODE] tags!)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1740
    
    2
Why will that last line not compile?
It's not part of any method.
If you're intending to launch this program like this:
java EmployeeMaker
then you can put your System.out.println( ... ) inside a "main" method like this:
public static void main( String[] args )
{
System.out.println (employee101.getLastName());
}
As to the
Employee1 employee101 =
Employee1 employee102 =
...
you can either (1) declare them static, so a static method such as main can access them, or (2) also put them in main.
Elaine Banks
Greenhorn

Joined: Dec 16, 2003
Posts: 18
Talk about a big fat DUH on that one....
Good Grief...look right past the obvious on that one! No main()!!!
It's obviously time for bed.
nite nite.
CB
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Fun with Constructors, etc
 
Similar Threads
TreeSet Question
Populate Complex Java Object using Reflection
Problem with refresh() method of EntityManamger in JPA
private constructor
How to set default values in an spring form input?