Results 1 to 4 of 4
  1. #1
    fermon is offline Member
    Join Date
    Nov 2014
    Posts
    5
    Rep Power
    0

    Default Java object question

    Hi coders, I'm a little new to Java and object creation. I have a question that maybe very simple to answer , but it has stumped me for a while now. Maybe I'm not googling the correct naming to get the best possible answer that makes sense.


    We'll here's my shot at explaining, when creating Objects I'm used to seeing code that looks similar to below.

    Object my_object = new Object();

    But quite frequently I see object's created using code similar below.

    TransportMapping transport = new DefaultUDPTransportMapping();


    The part that I'm missing is, I would expect to see the object created like below

    DefaultUDPTransportMapping transport = new DefaultUDPTransportMapping();

    Does the object reference variable "transport" point to an object of type DefaultUDPTransportMapping or TransportMapping?

    Im just looking for some explanation of creating objects like this ? It always throws me off when I see object created I assume with different class names .

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Java object question

    Any class object may be assigned to any class or interface type which exists in the classes inheritance hierarchy. So TransportMapping is either an inherited
    class or perhaps some interface of the DefaultUDPTransportMapping classes hierarchy.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    camel-man is offline Member
    Join Date
    Jan 2016
    Posts
    19
    Rep Power
    0

    Default Re: Java object question

    So essentially it points to DefaultUDPTransportMapping type object.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Java object question

    Yes. But it can only access the methods available to its type.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. ArrayList and object question
    By endgame in forum New To Java
    Replies: 2
    Last Post: 06-26-2014, 04:19 AM
  2. Object Orientation Question & scenario
    By dd09wrx in forum New To Java
    Replies: 0
    Last Post: 11-17-2013, 10:45 PM
  3. question about passing object by value (workaround)
    By joet1984 in forum New To Java
    Replies: 4
    Last Post: 03-01-2013, 02:58 PM
  4. object lock question
    By simon in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 04:36 PM
  5. Question about java object oriented Language
    By lenny in forum New To Java
    Replies: 3
    Last Post: 07-26-2007, 03:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •