CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Java Programming > Java Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Java Programming Ask your Java programming question and help out others with theirs.

    Closed Thread
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old January 12th, 1999, 02:29 PM
    Manoj Manoj is offline
    Junior Member
     
    Join Date: Apr 1999
    Posts: 1
    Manoj is an unknown quantity at this point (<10)
    Pass by value or reference



    HI. I am a C++ programmer mingrating to Java



    I have this query..Does Java support pass by value or pass by reference.

    Following code suggests that Java supports Pass by reference as it calls the &quot;callme &quot; function from the derieved

    class. But then it calls the constructor of the base class also which suggests that it makes a copy of base class...It

    means its pass by value..

    Please help


    class Base {

    Base(){

    System.out.println(&quot;I am in base class constructor &quot;

    }

    void callme(){

    System.out.println(&quot;I am in base class&quot;

    }



    }

    class Derieved extends Base {

    void callme(){

    System.out.println(&quot;I am in derieved class&quot;

    }

    }


    class dispatch {

    public static void main(String args[]) {

    Derieved dd = new Derieved() ;

    fff(dd);

    }

    }



    static void fff(Base bb){

    bb.callme();

    }

    }




    OUTPUT is

    I am in base class constuctor

    I am in base derieved class




      #2    
    Old January 12th, 1999, 04:58 PM
    Zafir Anjum Zafir Anjum is offline
    Member
     
    Join Date: May 1999
    Posts: 93
    Zafir Anjum is an unknown quantity at this point (<10)
    Re: Pass by value or reference



    Java (almost) always uses pass by reference. The only time it uses pass by

    value is for int, boolean, char etc. Note that in Java all access to an object

    is through its reference.


    The first line of output you get is when the Derived class is constructed. As in

    C++, the subclass construction continues only after the base class portion gets

    constructed.


    The second line of output of course is from the callme() of the Derived class.
      #3    
    Old February 9th, 2001, 07:29 AM
    vinjava vinjava is offline
    Junior Member
     
    Join Date: Feb 2001
    Location: india
    Posts: 2
    vinjava is an unknown quantity at this point (<10)
    Re: Pass by value or reference

    Mr. Manoj

    the out put is
    I am in base class constructor
    "I am in base class"

    b'coz u r calling the method of the base class using it's object obviously the result is as above and the constructor is calls by default when ever u create ad nobject of the class



    vinay kumar s.v
    Closed Thread

    Bookmarks
    Go Back   CodeGuru Forums > Java Programming > Java Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:32 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009