Results 1 to 4 of 4
  1. #1
    crown.clown is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default 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
    Last edited by crown.clown; 08-29-2012 at 11:42 AM. Reason: Fonts are too big.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default 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.

    ** This space for rent **

  3. #3
    crown.clown is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: Hello I'm new to this forum :)

    Thanks. Finally figured this out with your advice in 20 minutes. Greatly appreciated. :)

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Hello I'm new to this forum :)

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. New to this forum
    By thestranger in forum Introductions
    Replies: 6
    Last Post: 07-27-2008, 09:53 AM
  2. hello forum....
    By Vijay Swaminatha in forum Introductions
    Replies: 3
    Last Post: 06-29-2008, 05:58 AM
  3. Welcome to our new forum: Forum Lobby
    By JavaForums in forum Forum Lobby
    Replies: 18
    Last Post: 02-07-2008, 05:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •