CrazyEngineers
  • Question about constructor?

    Morningdot Hablu

    Morningdot Hablu

    @morningdot-6Xuj4M
    Updated: Oct 27, 2024
    Views: 997
    What do you think constructor can return a value i.e "0(void)" or constructor can never return return a value???
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • gaurav.bhorkar

    MemberAug 18, 2010

    A constructor can never return a value, it hasn't got any return type.
    Are you sure? This action cannot be undone.
    Cancel
  • Morningdot Hablu

    MemberAug 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);
    }
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Kaustubh Katdare

    AdministratorAug 18, 2010

    Thread moved to CS/IT Engineering section.
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberAug 18, 2010

    mohit007kumar00
    Correct gaurav constructor can never return any valu.
    like this
    I answered with reference to C++, not sure about other OO languages though.
    Are you sure? This action cannot be undone.
    Cancel
  • Morningdot Hablu

    MemberAug 18, 2010

    @Gaurav same here in the case of java also gaurav.
    Are you sure? This action cannot be undone.
    Cancel
  • anandkumarjha

    MemberAug 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????
    Are you sure? This action cannot be undone.
    Cancel
  • Morningdot Hablu

    MemberAug 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.
    Are you sure? This action cannot be undone.
    Cancel
  • Voltaire

    MemberAug 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?
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register