Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Hello I'm new to this forum :)

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    90
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default 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
    Last edited by Samaras; August 29th, 2012 at 05:08 AM.

  3. #3
    Member
    Join Date
    Jul 2012
    Posts
    90
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default 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

Similar Threads

  1. New to Forum.
    By CurseControl in forum Member Introductions
    Replies: 1
    Last Post: March 20th, 2012, 01:34 PM
  2. Hello every one in this forum.
    By neradabilli.sridhar in forum Member Introductions
    Replies: 1
    Last Post: March 5th, 2012, 04:57 AM
  3. Hello forum!
    By f.java in forum Member Introductions
    Replies: 1
    Last Post: June 1st, 2011, 06:25 AM
  4. New to forum
    By cxlizard in forum Member Introductions
    Replies: 0
    Last Post: December 19th, 2010, 03:35 PM
  5. Didn't see this forum... but hey!
    By Lord.Quackstar in forum Member Introductions
    Replies: 2
    Last Post: June 10th, 2010, 11:42 AM