I can see two compilation errors, plus a large pile of style errors.
This line:
return System.out.println("ID: "+ID + " First Name: "+FirstName+
" Last Name: " +LastName+" Marital Status: "+ StringStatus +
" Age: "+Age);
1) The variable StringStatus
has not been declared.
1a) You then changed that to (String) Status
which is also incorrect because you can't cast a MaritalStatus
to a String
. (But you can call toString()
on it ....)
2) The println
method is a method that returns void
not a String
.
The primary style errors1 are:
- Field names should NOT start with an uppercase letter.
- Your use of whitespace before / after tokens is non-standard and inconsistent. Put a single space before and after infix operators like
+
and =
. No spaces before a ,
and one space after.
- Use of a 150+ character line is non-standard ... and makes your code hard to read. At most 80 character lines is best for maximal readability.
- Indenting by 8 spaces is excessive.
Fields should be private
not protected
.
This more than simply style. If you don't declare a field as private
, then a subclass or (worse) some other unrelated code could potentially interfere with the field's value. That means that you have to read a lot more code to understand what might be going on when you are tracking down a bug (for example). Using private
helps to encapsulate the type, which makes the code easier to read, and easier to reason about.
IMO, the best way to deal with parameter names and field names that are the same (e.g. in a constructor) is like this:
public class Person {
protected int id;
public Person(int id) {
this.id = id; // Use 'this' to disambiguate the two meanings
// of the 'id' identifier.
}
}
1 - Unfortunately, some "helpful" person has corrected a lot of this to make the code in your question readable. Please refer back to the stuff you posted originally.