Question about constructor?

What do you think constructor can return a value i.e "0(void)" or constructor can never return return a value???

Replies

  • gaurav.bhorkar
    gaurav.bhorkar
    A constructor can never return a value, it hasn't got any return type.
  • Morningdot Hablu
    Morningdot Hablu
    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
    Thread moved to CS/IT Engineering section.
  • gaurav.bhorkar
    gaurav.bhorkar
    mohit007kumar00
    Correct 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
    @Gaurav same here in the case of java also gaurav.
  • anandkumarjha
    anandkumarjha
    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
    @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
    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?

You are reading an archived discussion.

Related Posts

😕wat is the procedure of scholarship via GRE score?n wat is the process to choose an appropriate university?
Press Release: - Sequoia Capital India, today announced that it has invested INR 60 crore in Quick Heal Technologies, India’s leading provider of computer security software products. This investment will...
What is the concept of green building?
Hello everybody, I have a UPS connected to my PC with this specs (INPUT 162-290VAC 50-60hz OUT:220VAC+-%10 50-60+-%1 transfer time 2-6ms battery 12V/7AH * 1) yet this seems very ineffective...
Best method & most common and useful method of concrete design