Results 1 to 4 of 4
Thread: Hello I'm new to this forum :)
- 08-29-2012, 11:41 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
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. :DLast edited by crown.clown; 08-29-2012 at 11:42 AM. Reason: Fonts are too big.
- 08-29-2012, 11:44 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Hello I'm new to this forum :)
Your fields are (quite correctly) private.
That means you cannot access them directly from outside the Author class.
However, your Author class provides methods that allow you to get at this information...those are the getters.
So use them instead of trying to access the attributes directly.Please do not ask for code as refusal often offends.
- 08-29-2012, 12:02 PM #3
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
Re: Hello I'm new to this forum :)
Thanks. Finally figured this out with your advice in 20 minutes. Greatly appreciated. :)
- 08-29-2012, 02:24 PM #4
Re: Hello I'm new to this forum :)
Forum Rules -- particularly the third paragraph
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
New to this forum
By thestranger in forum IntroductionsReplies: 6Last Post: 07-27-2008, 09:53 AM -
hello forum....
By Vijay Swaminatha in forum IntroductionsReplies: 3Last Post: 06-29-2008, 05:58 AM -
Welcome to our new forum: Forum Lobby
By JavaForums in forum Forum LobbyReplies: 18Last Post: 02-07-2008, 05:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks