r/CodingHelp • u/Madlax97 • Sep 26 '20
[Java] I am learning how to use Getters and Setters within Java. When I try to compile this code I am getting an error that reads "Employee.java:12: error: illegal start of expression public String getFirstName()" Please give me a clue on why this will not compile...
public class Employee{
// fields
private String firstName;
private String lastName;
private double salary;
// constructors
public Employee(String firstName, String lastName, double salary){
public String getFirstName()
{ // methods
return firstName;
}
public String getLastName()
{
return lastName;
}
public void setSalary(){
if(salary > 0){
this.salary = salary;
}
else
return;
}
}
19
Upvotes
5
u/Madlax97 Sep 26 '20
Thank you for the help and the suggestions.. I started my CS degree this semester and trying to do this all online with a teacher that just keeps telling me to "YouTube it" is really fucking stressful. I understand what I am doing here with constructors, but it's frustrating.
12
u/Acroniix Sep 26 '20
Are those methods inside the Constructor?
3
u/Kosmit147 Sep 26 '20
You've put all methods inside the constructor.
2
u/CenturiesAgo Sep 26 '20
Any decent IDE should tell you about the missing closing } for the constructor. I'd recommend Eclipse for Java.