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 2 of 2

Thread: constructor issue

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

    Default constructor issue

    hi
    say i wanna write a constructor that would pass parameters (of a simple type) to an object
    say the parameters are (double)x y and z and the object is a Point3D object that has _x, _y and _z as attributes
    should i use a method like setX() to pass the parameters to the object or should is use the object's constructor and pass these parameters to the constructor?
    in other words should i:

    public Box3D (double length, double width, double height, double x, double y, double z){ //_basicCorner is an object.
    _length = length;
    _width = width;
    _height = height;
    _basicCorner = new Point3D (x,y,z);

    or should i:

    public Box3D (double length, double width, double height, double x, double y, double z){
    _length = length;
    _width = width;
    _height = height;
    _basicCorner.setX(x);
    _basicCorner.setY(y);
    _basicCorner.setZ(z);

    thanks in advance and hope i made myself clear despite english not being my native language.


  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: constructor issue

    if _length and others are private then use set method but i don't think they make a difference until that class is for public(not the keyword) use.

Similar Threads

  1. which class has a default constructor? (Req. guidance on constructor)
    By DragBall in forum Java Theory & Questions
    Replies: 1
    Last Post: June 27th, 2012, 04:42 PM
  2. Java Issue / Cache issue
    By VisualPK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2012, 08:43 PM
  3. Constructor
    By kbbaloch in forum Object Oriented Programming
    Replies: 6
    Last Post: February 1st, 2012, 11:40 PM
  4. Constructor help
    By sambar89 in forum Object Oriented Programming
    Replies: 3
    Last Post: November 26th, 2011, 11:17 PM
  5. [SOLVED] Cannot Find Constructor
    By jrookie in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 8th, 2010, 02:54 PM