Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • gaurav.bhorkar

    gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Aug 18, 2010

    A constructor can never return a value, it hasn't got any return type.

  • Morningdot Hablu

    Morningdot Hablu

    @morningdot-6Xuj4M Aug 18, 2010

    Correct gaurav constructor can never return any valu.
    like this

    public class r
    {
    int p;
    public void r(int k)//Show an error because here constructor should return a valu that is "0"(void);
    {
    p=k;
    System.out.println("p= "+p);
    }
    public static void main(String args[])
    {
    r t=new r(5);
    }
    }
  • Kaustubh Katdare

    Kaustubh Katdare

    @thebigk Aug 18, 2010

    Thread moved to CS/IT Engineering section.

  • gaurav.bhorkar

    gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Aug 18, 2010

    mohit007kumar00Correct gaurav constructor can never return any valu.
    like this

    I answered with reference to C++, not sure about other OO languages though.

  • Morningdot Hablu

    Morningdot Hablu

    @morningdot-6Xuj4M Aug 18, 2010

    @Gaurav same here in the case of java also gaurav.

  • anandkumarjha

    anandkumarjha

    @anandkumarjha-jzdDMA Aug 20, 2010

    hello everyone,
    System.out.println("the value of c is="+c);
    as we know here that here +sign appends the value of c to the string which preceids it i.e if the value of c is in the form of integer the firstly it is being converted to string.why is it so??
    can anyone please justify that for me????

  • Morningdot Hablu

    Morningdot Hablu

    @morningdot-6Xuj4M Aug 21, 2010

    @anand here in java "+" is an operator which is used to add or concatenate two strings objects that's why c is converted to string.

  • Voltaire

    Voltaire

    @voltaire-4MxWke Aug 24, 2010

    You fellas are much more up to date with this stuff than me, but thinking back to Pascal...
    p = ^t;
    t = type
    constructor init;
    destructor done; virtual;
    end; {type}
    if new(p,init()) <> nil then...

    So, I think the constructor returns a pointer if successful and nil when not.

    Any better ideas?