Instantiating an object without an assignment

Hi,
I am learning Java. I would like to know what is the significance of instantiating an object without an assignment.
I have created a class TestClass1 with a single constructor that prints a test message.
In TestClass2, if I write "new TestClass1()" rather than "TestClass1 x = new TestClass1()" it still works, and prints the test message.
I would like to know if I do not assign an object at the time of instantiation, it cannot be referenced or reused later, then what is the significance of this type of construct and when it can be useful, and where is the object being held.
public class TestClass1 {
   TestClass1() {
     System.out.println("This is a test message");
public class TestClass2 {
  public static void main (String... args) {
    TestClass1 x = new TestClass1();  //This prints "This is a test message"
    new TestClass1();                 //This also prints "This is a test message"
    String y = new String("abc");  //this makes sense
    //The following does not throw an exception - what purpose could this conceivably serve
    new String("def");               

SRAY01 wrote:
Sorry for using the wrong terminology - I mean a method is invoked rather than instantiated.
A Constructor can be treated as a special type of method to instantiate an object of the class - but it does not have any expressed return type - so I assumed it implicitly returns an object (of same type as the class the contructor belongs to).
But syntactically its usage is sort of similar to invoking a method (apart from the "new" keyword).
I was wondering how is it possible that a constructor or a method with a return value could be called in a code without an assignment. I assumed it should be possible only for void type of methods.
But apparently its a feature of Java. This feature is very different from any programming language I have worked with so far, e.g. PL/SQL where you cannot call a function with a return value without assigment.
No the constructor doesn't 'return' anything.
Construction is done by the new expression.  As PART of the execution of the new expression the constructor is called.  The new expression does other things besides just call the constructor.  For instance it allocates space and it is also responsible for returning the object.  And this is also true for languages like C# and C++ as well.

Similar Messages

  • Instantiation of objects -- create new space inmemory?

    If I have this:
    lPerson : person = new;
    lPerson.name.setValue('Martin');
    lPerson.phone.setValue('2762109');
    lPerson = new;
    Does this second instantiation create a new copy of "lPerson" in memory?
    Does it destroy the old? Does it create and destroy in the exact same
    memory address?
    -Martin

    In a message dated 97-08-02 00:08:50 EDT, [email protected] (Martin
    Nystrom) writes:
    << If I have this:
    lPerson : person = new;
    lPerson.name.setValue('Martin');
    lPerson.phone.setValue('2762109');
    lPerson = new;
    Does this second instantiation create a new copy of "lPerson" in memory?
    Does it destroy the old? Does it create and destroy in the exact same
    memory address?
    >>
    IPerson is just an Object Reference (similar to a Pointer). Initially it
    points to nothing and is considered NIL (if IPerson = nil then ...). Now you
    can get the IPerson reference to point to an object either by assignment or
    by instantiation.
    In assignment (IPerson = anotherPerson; ) the Object reference is assigned to
    point to the same Object that the assignor (?) reference points; note that it
    points to the object and not the reference (in effect there are no pointers
    to pointers).
    Instantiation is somewhat similar. The =new( ) syntax creates an Object
    instance and then the reference is assigned to point to it. So doing a
    second =new( ) would create a second object instance and the reference would
    be assigned to it. If the first object instance was not referenced by
    anything else then you have no way of getting a handle on it. It is
    considered garbage and forte will garbage collect the memory at some point.
    In your example, the first IPerson object goes AWOL at the second =new( ) and
    your IPerson reference is left pointing to a new 'empty' Object which is
    somewhere else in memory.
    Rob.

  • Certificates using serial numbers with material without batch assigned

    Hi experts...how can i track serial numbers and inspection lots from roh material without batch assign but with serial numbers ? these roh materials were used in PO without batch assign to FERT material yet. Is possible use where-used list only to manage serial number or only using batch administration over the serial numbers ?
    i will apreciatte any answer!
    Regards
    Marco Antonio Trois Endres

    Hi ,
    This seems to be a Material Management configuration question, I dont know if this will answer it
    You will have to configure the Characteristics of your Material from a task list and transfer/Copy it to your Certificate profile,
    there has to be a feature to enter the desired selection Criteria based on your question
    Work with the security team if  your MM_G and MM_S class objects can help open or close certain authroization objects to achieve your goal.
    in one of the google search it states that
    "This can be done from  Extras Characteristics from  your task list.
    A dialog box appears for entering the selection criteria for the task list"
    Will Need more security related information to help you on this.

  • 13.02 update changes smart object / icc profile assignment behavior?

    Since updating to the 13.02 release of photoshop CS6 extended I have noticed the following modified behavior:
    When changing the assigned profile of an image containing smart objects, where the smart objects have previously gone through a color profile conversion - the smart objects will get reconverted to the newly assigned profile.
    This was certainly not the behavior of 13.01 and previous versions.
    Is this an intentional change?  If it is shouldn't it be noted in the release notes?
    System info: mac os x 10.6.8

    I think I understand the rational for this change, but I think it misses the mark a bit.
    In my experience the largest source of smart-object trouble is when someone converts a document without first assigning a profile, relying on the profile set in photoshop's color settings.  When the smart-object is edited on another computer the color will shift if the color settings on the two computers don't match exactly.
    By reconverting smart objects on profile assignment you are creating two new problems. 
    Only smart objects are reconverted, so documents with both smart and not-smart layers will end up in an inconsitent state.  Colors that matched within the same image may no longer match.
    If a document is saved without a profile assigned and you later want to assign it a profile, you will have to use the original profile or your color will shift.  It is not uncommon when working with documents from other organizations that the original profile used for conversion is not available.
    What then is the fix for this problem?  Always embed the profiles used for conversion within the smart objects for use when updating.  Source and destination.

  • Re:  "Item category K can only be used without account assignment"

    Hi,
    while creating PO from PR the following error is coming.
    "Item category K can only be used without account assignment"
    How to solve this
    Regards,

    Hello,
    Item category K cannot be used with an account assignment as the goods are not physically used in the company. The stock is stilla consignment stock and belongs to vendor. Using an account assignment will book the cost in the company's expenses.
    use an account assignment if required when you transfer from consignment to own stock.
    Hope this helps,
    Regards,
    VS

  • Profit center for purchase order without account assignment

    I've requirement to include profit centers in purchase orders without account assignment category.
    The trouble is when there is no profit center maintained in material master.
    Is there a way to determine profit center in purchase order for such cases?

    Dear Abinash,
    Define substitution in GGB1 at line item level as shown below:
    Prerequisite : BSEG-WERKS = Maintain plant
    Substitution : BSEG-PRCTR = maintain profit centre as constant value
    After define it, assign to the co.code.
    Regards,
    Mukthar

  • Anchor Object without Modifying Text

    Short:
    Is there a way to place objects and attach their location to a particular numbered paragraph, without using anchored objects, i.e., is it possible ot make an anchored object without a inserting an anchor into the text?
    Long:
    I am currently assembling a document where the text is placed from a Microsoft Word document and figures will be placed from a variety of sources (.pdf exports of TeX equations, .ai figures, etc.).
    I have explored anchored objects to some extent, and they provide all the functionality I need, with one exception.
    I would very much like to be able to insert figures into my indesign project and be able to update my text in Microsoft Word without losing the insertion points. As it is now, when I update my linked Word file, the anchors are removed from the text.
    One approach I considered was to complete the majority of the text in Word, then place the text into InDesign, break the link, add my anchors, and complete revisions in InDesign. Unfortunately, this approach will not work, as I am using a reference manager in the text, and reordering/adding/removing references would become exceedingly tedious in a document with dozens of references and nearly 100 citations to those references.
    Thanks so much for your help in advance!

    Short: No.  Longer:  Perhaps you should just put the objects on the page, or pasteboard, for now, and do the anchoring when editing is done.

  • "In initializer for 'mxmlContent', type Object is not assignable to target Array element type..."

    Hi all,
    So I've have built an application on flash builder 4.5 using Christophe Coenraets' tutorial "Building an EmployeeDirectory" (http://www.adobe.com/devnet/flex/articles/employee-directory-android-flex.html#articlecont entAdobe_numberedheader).
    I'm getting this error message "In initializer for 'mxmlContent', type Object is not assignable to target Array element type mx.core.IVisualElement." and then the debugger highlights my code this line of my code "</s:List>" in my EmployeeDetails.mxml file. This started after I coded Part 5, Step 2 "Integrating with the Device Capabilities: Triggering the Actions".   The rest of the code debugged fine.
    I think it relates to Christophe's note "Note: Make sure you import spark.events.IndexChangeEvent (and not mx.events.IndexChangedEvent) for this code to compile.".  I don't know where to place this
    " import spark.events.IndexChangeEvent;" line of code. 
    Any help?  Tks in advance..
    Any help would be greatly appreciated.  Thanks

    You have a DataGrid directly inside a State element. Perhaps wrap it in an AddChild element?
    More information on using states can be found here:
    http://livedocs.adobe.com/flex/3/html/help.html?content=using_states_1.html

  • Replace message payload object without remove queue table

    hi,
    i want to replace message payload object without remove queue table but i have got the "ORA-02303: cannot drop or replace a type with type or table dependents" error.
    is there any way to replace message payload object without remove queue table?
    Click to link below to find a demo which is explain the problem clearly
    Replace message payload object without remove queue table
    Regards.

    Hi
    I answered this in Re: Replace message payload object without remove queue table forum.
    Cheers, APC

  • Edit message payload object without remove queue table

    Hi, need ur help again,
    Known that if we want to modify a message payload attribute (add,edit or delete), we will fail to do so if the message payload is used by existing AQ's queue table.
    How to change the message payload object without remove the queue table?
    Thanks!

    Hi
    I answered this in Re: Replace message payload object without remove queue table forum.
    Cheers, APC

  • ODI-1228: ORA-22950: cannot ORDER objects without MAP or ORDER method

    Simple interface between two schemas in the same oracle database (10g)
    I am trying to copy one table and do one simple lookup (in a table located in 3rd schema on the same database)
    Integration task fails on
    ODI-1228: Task messagexml_document (Integration) fails on the target ORACLE connection S2_P1.
    Caused By: java.sql.SQLException: ORA-22950: cannot ORDER objects without MAP or ORDER method
    Can anybody tell me, what I am doing wrong? Code that generate this error is just a simple INSERT with SELECT and sub SELECT with JOIN?
    I just can't find anything about this error.
    I'm stuck :-(

    I discovered that one of my fields is an XMLType field and is a part of comparison ODI do when it tries to do incremental update. The error message here is just a message from db that it can't compare XMLType fields to each other.
    Is there any way to learn ODI to not to compare by XMLType field?

  • No POWL object types are assigned to you. Please inform your system admin

    Hi experts,
    We are on SRM 7.0 and ECC 6.0.
    We are using netweaver 7.0 (SP7) for our portal instance. SSO, UWL etc have been configured in the Portal.
    Now when the user logs in to create a shopping cart and clicks on the Employee Self Service link, he gets the following error:
    "No POWL object types are assigned to you. Please inform your system adminstrator"
    What could be the resolution for this?
    Regards

    Hi Jay,
    Thanks for the update.
    There were 2 roles for employee in portal. I changed the role. The one with details pcd:portal_content/com.sap.pct/specialist/com.sap.pct.srm.srm70/com.sap.pct.srm.core.fl_core/com.sap.pct.srm.core.fl_roles/com.sap.pct.srm.core.ro_employeeselfservice worked.
    I did not have to maintain the settings for 'Defining query visibilty at role level'.
    However now once the shopping cart has been ordered, I come back to check it's status under the ESS link, I see that it is awaiting approval, but when I try to open the SC, it does not open.
    Also I am unable to open the SC if I search it under 'Advanced Search'.
    Any inputs on what could be the reason?
    Regards

  • Trying to get a handle to an object using CVI_ActiveApp, but it opens a new CVI everytime it runs. Is there a way to get a handle to an object without it opening up a new CVI?

    I'm trying to get a handle to an object using CVI_ActiveApp. It works, but it opens a new CVI application when it is run using the command line. Is it possible to get a handle to an object without a new CVI application opening up?

    Hi,
    In the help documentation for the CVI_ActiveApp function, it states:
    "If the server application is already running, this function may or may not start another copy of the application. This is determined by the server application."
    http://zone.ni.com/reference/en-XX/help/370051P-01/cvi/usermanual/actxappactiveapp/
    I don't believe you have control over whether or not a second instance is started.
    Regards,
    Lindsey W. | Applications Engineer | National Instruments

  • Put on account without reference assignment.

    After completion of the payment design F110 are some types of documents (the order for costs) put on account without reference assignment.
    This problem occured after recording SAPKB46C15.      
    Many thanks for your help.

    My understanding of offers..... The $300 Reward Card for triple play services is an ONLY offer, meaning no monthly discount being applied. No 12 month commitment, cancel anytime without $180 Early termination fee.This is primarly for short term user who knows that service time will be limited. The $150 Reward Card for triple play is with discount offer. You may request to give up your $50-60 a month discount, to receive the $300 Reward Card but will be hundreds of dollars behind in savings over 12 month contract. http://www.att.com/u-verse/explore/offer-details.jsp

  • Good receipt with/without GR assignment

    Dear all,
    I am little puzzle to get an understanding in difference between...
    Goods receipt with GR assignment
    and
    Goods receipt without GR assignment.
    Can please anyone let me know in details.
    Thanks a lot in advance,
    Cheers!

    perhaps let me be more clear.
    above query is related to Confirmations -related goods issue.
    In customization-in purchasing- under confirmation- under set up conformation control .............there is an indicator to select / or not to select GR assignment indicator ...............in order to post the GR with reference to vendor confirmations.
    I wanted to enquire why and what is the functionality of this GR assignment and how system is going to react ........when we do select OR when we do not select that indicator.
    Hope this well help any body to get some idea of my query.
    Cheers!

Maybe you are looking for

  • What is the Part Number for the Lenovo Y500-9541 120V AC Adapter?

    Lost my adapter. I want to get a genuine OEM AC adapter for the single video card version of the Y500. Can someone take a look at their adapter and give me the P/N or model number?

  • BI Publisher 11g has terrible monitoring capability.

    I think all I need to post is the following line and people will know what I'm talking about: weblogic.kernel.Default (self-tuning)' has been busy for "703" seconds working on the request "weblogic.servlet.internal.ServletRequestImpl@376d9e05[ The da

  • Acrobat Distiller

    Acrobat distiller x is not getting open .how to open it, it will show the acrobat distiller screen and log off

  • Best way to produce video for youtube

    Hi all I am a newbie here but wondered if anyone has any tips for using PE4 to produce high quality youtube video. I am capturing HDV from a Canon HV30. (As aside if anyone has any questions about how to get the HV30 / PE4 combination to work, please

  • Sharing video--transfering files on the web HELP!

    I am doing some video projects with some people that live far away. Where on line can I set up an account where my friends can upload the file (their video), then I can download it and add it to my projects. Any place free? Need large spaces for vide