#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    13
    Rep Power
    0

    Is a Constructor redundant if it a set method does exactly the same thing?


    Code:
    public class GradeBook
    {
        private String courseName;
    
        public GradeBook(String name)
        {
             courseName = name;
        }
    
        public void setCourseName( String name )
       {
            courseName = name;
       }
    In this situation, are they both the same? Thanks.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    The set method would allow the name to be changed after the object was built giving the class more options in its use.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    13
    Rep Power
    0
    Thanks NormR.

IMN logo majestic logo threadwatch logo seochat tools logo