Hello I'm new to this forum :)
And I do have this question, any help would be appreciated. The problem is that I don't have an idea where I'm wrong.
public class Author { //opening statement
private String name;
private String email;
private char gender;
private char m, f;
//constructors (overloaded)
public Author(){ //1st constructor
name = "John Smith";
email = "John.smith@yahoo.com";
gender = m;
}
public Author(String n){
name = n;
email = "John.smith@yahoo.com";
gender = m;
}
public Author(String n, String e){
name = n;
email = e;
gender = m;
}
public Author(String n, String e, char g){
name = n;
email = e;
gender = g;
}
//public methods
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public char getGender() {
return gender;
}
public String toString() {
return name + "(" + gender + ") " + "at " + email;
}
} //closing statement
Here is the other code:
public class TestAuthor { //save as TestAuthor.java
public static void main(String[] args){
Author a1 = new Author();
System.out.println(a1.name + "("
+ a1.gender + ") " + "at " + a1.email);
} //main closing statement
} //class closing statement
The errors are:
The field foo: is not visible for my 3 private variables.
Procedures done: Already searched for the problem in google:
Supposed answers:
-It's not in the right package (I think it is)
Advice would be of great help. Thank you. :D
Re: Hello I'm new to this forum :)
Try wrapping your code like this [key]//here your code[/key] Replace key with code in order this to work
Also which is the name that you have given to your project?
PS-welcome :D
Re: Hello I'm new to this forum :)
Ok i copy pasted the code in an IDE.However it very helpful for others to wrap your code.
First class Author can not be public,so remove the public word.In your main you can not of course access the fields of class Author,so use the geters functions you have.You can not access them because they are declared as private.
If you want the Author class to be public,i would suggest you to creating another file named Author.java and in first line of this file write package testauthor; ,if we say that the project is named TestAuthor