Results 1 to 2 of 2
Thread: Constructor Error
- 03-20-2011, 07:45 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 28
- Rep Power
- 0
Constructor Error
Working on inheritance & Polymorphism. I have an Employee class which has a private MyDate dateHired variable. MyDate class extends to the "Employee class" which has methods which used in the Employee class. When I compile the MyDate class is getting the following errors:
')' expected
illegal start of expression
When I try to compile my Employee class it is referring me to MyDate class with these errors:
Resource MyDate.java
')' expected
illegal start of expression
cannot find symbol variable MyDate
There are 2 more classes Staff & Faculty, but they inherit constructor from Employee which does not compile cleanly so I cannot go on.
I know I am missing something and now all I can see are letters and not making sense. Can someone please help me see what I am missing? Example would be greatly appreciated.
Java Code:public class Employee extends Person { private String office; private int salary; private MyDate dateHired; public Employee () {} public Employee(String name, String address, String phone, String email,String office, int salary, MyDate dateHired) { super(name,address,phone,email); this.office=office; this.salary=salary; this.dateHired=dateHired; } public String getOffice() { return office; } public int getSalary() { return salary; } public String setOffice() { return office; } public int setSalary() { return salary; } public String toString() { return super.toString() + "\nOffice:" + this.office + "\nSalary:" + this.salary + "\nDate Hired" + dateHired.getMonth() + "/" + dateHired.getDay() + "/" + dateHired.getYear(); } }
Java Code:public class MyDate extends Employee { int year; int month; int day; public MyDate() {} public MyDate ( String office, int salary, MyDate dateHired,int year, int month, int day) { super(office, salary, MyDate dateHired); /// are of error this.year=year; this.month=month; this.day=day; } public int getDay() { return day; } public int getMonth() { return month; } public int getYear() { return year; } public boolean setDMY(int day, int month, int year) { boolean valid = day >= 1 && day <= 31 && month >= 1 && month <= 12; if (valid) { day = day; month = month; year = year; } return valid; } public String toString () { return super.toString()+ "Month: " + month + ", Day: " + day + ", Year: " + year + "]"; } }
-
First and foremost, your design is wrong: MyDate should definitely not extend Employee. Fix that first and get all the Employee stuff out of the MyDate constructor.
Similar Threads
-
Junit3 error: Implicit super constructor TestCase() is not visible
By albertkao in forum Advanced JavaReplies: 3Last Post: 01-21-2011, 01:37 PM -
constructor error in image manipulation app
By bmcnamara in forum New To JavaReplies: 3Last Post: 12-05-2009, 08:06 PM -
Constructor Error ?
By sysout in forum New To JavaReplies: 4Last Post: 08-25-2009, 05:39 AM -
why do I got this error about the constructor ?
By aneuryzma in forum New To JavaReplies: 4Last Post: 08-14-2008, 10:22 PM -
Error: cannot find symbol constructor
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 08:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks