Results 1 to 2 of 2
  1. #1
    sonal is offline Member
    Join Date
    Nov 2007
    Posts
    4
    Rep Power
    0

    Default Need help with a question please

    I am currently working through a java book and would like some help in understanding the following question:-

    Exercise 2.19 Suppose that the class Pet has a field called name that is of type
    String. Write an assignment statement in the body of the following constructor so
    that the name field will be initialized with the value of the constructor’s parameter.
    public Pet(String petsName)
    {
    ...
    }


    Thanks in advance, I am really keen to get my head round this and would appricate any help

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    class Pet
    {
        // a field called name that is of type String
        String name;
    
        public Pet(String petsName)
        {
            // assignment statement so that the name field
            // will be initialized with the value of the
            // constructor’s parameter
            name = petsName;
        }
    }

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. JSP Question
    By maheshkumarjava in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 10:51 AM
  3. Need help on this question
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-27-2008, 03:58 PM
  4. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 10:18 AM
  5. question about rmi
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 04:19 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
  •