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

Thread: Passing as a parameter, an object + another variable

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

    Default Passing as a parameter, an object + another variable

    I'm have trouble an object which has three integer values in it along with another parameter which is simply a double. This is my syntax atm:

    Object newObject = new Object((1,-2,35),.5);

    I'm not sure how this is supposed to be written out in order for the object to accept it. Thank you in advance for any assistance you may provide!


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Passing as a parameter, an object + another variable

    No, you cannot have nested parenthesis like that. Perhaps all you need to do is to remove the inner nested parenthesis and this will work. The key will be to inspect the constructors available for this class and to call one of them appropriately. By the way, hopefully your class is not named "Object", right?

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Passing as a parameter, an object + another variable

    Nah it isnt called object, im just generalizing the statement...but i checked out the constructor and it seems to be in the correct order and the parenthesis idea didnt work

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Passing as a parameter, an object + another variable

    Um.... care to share the constructor with us?

  5. #5
    Junior Member
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Passing as a parameter, an object + another variable

    public class Object {
     
    	private Coord3D origin;
    	private double intensity; // In range [0..1]
     
    	public Light (Coord3D origin, double intensity) { 
    		this.origin = origin;
    		this.intensity = intensity;
    	}

  6. #6
    Member
    Join Date
    Jul 2012
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Passing as a parameter, an object + another variable

    Wouldn't it just be:

    Light light = new Light(new Coord3D(object), 5);

    ??

  7. The Following User Says Thank You to Tyluur For This Useful Post:

    curmudgeon (December 11th, 2012)

  8. #7
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Passing as a parameter, an object + another variable

    Indeed you would need to pass a Coord3D object into the Light constructor, likely

    Light light = new Light(new Coord3D(1, -2, 35), 0.5);

    Or something similar.

Similar Threads

  1. Method calculate 2 object using constructor with parameter
    By DavidXCode in forum Object Oriented Programming
    Replies: 2
    Last Post: November 21st, 2012, 09:31 PM
  2. Need help with passing user defined variable in SQLJ
    By redkryptonite in forum JDBC & Databases
    Replies: 1
    Last Post: March 7th, 2012, 05:47 AM
  3. Need help with parameter passing in my project? (Beginner)
    By xlFireman in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 14th, 2012, 01:10 AM
  4. Passing JTextField as String parameter
    By Christophe in forum Java Theory & Questions
    Replies: 3
    Last Post: April 11th, 2010, 05:32 AM
  5. Passing objects as a constructor parameter
    By derky in forum Object Oriented Programming
    Replies: 2
    Last Post: October 27th, 2009, 04:31 AM