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

Thread: Object as an attribute and constrcutor

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Object as an attribute and constrcutor

    I am not sure how to delete this thread, but I essentially posted an answer to an assignment and that wasn't my intent.
    Last edited by hjherron; July 16th, 2020 at 01:25 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Object as an attribute and constrcutor

    I can't fill in the "engine" argument.
    Please explain what you tried to do and what happened. Post the full text of any error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2020
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Object as an attribute and constrcutor

    Using the code I have above it requires three arguments the make, model and Engine. Engine is an object not a string or a double or anything like that so I can't type anything in that area (the last spot after the comma in Accord)
    Car car1= new Car("Honda","Accord","");
    I'm not getting an error code, other than "expression expected"

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Object as an attribute and constrcutor

    The assignment says: Note engine is an object of the Engine class.
    Where is the definition for the Engine class?
    Why does the code define a variable: Engine as an instance of the Objects class. The code should NOT be using the Objects class.
    The variable engine(Not Engine) should be defined as an Engine object, not an Objects object.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Object as an attribute and constrcutor

    I think I have it fixed now.
    Good.

    Please be sure to use proper code tags when posting code. I added []s to your attempt at tags.
    http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    hjherron (July 16th, 2020)

Similar Threads

  1. How to retrieve an object from a session attribute
    By jaltaie in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: September 3rd, 2013, 07:08 AM
  2. Replies: 149
    Last Post: February 19th, 2013, 10:04 PM
  3. Replies: 1
    Last Post: February 14th, 2013, 07:30 PM
  4. not able to get the context attribute set in ServletContextListener
    By jkoder70014 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: August 17th, 2011, 11:47 AM
  5. [SOLVED] XML get/set node by attribute value
    By b_jones10634 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 24th, 2010, 11:26 AM