Class t3{ int i; static public void main( String a[]) { int j=8; t3 t= new t3(); new t3().disp(j); } //constructor overloading t3() { System.out.println("Enter to t3"); //this.disp(); } void t3() { System.out.println("Enter to t3 void"); }}On what situation void type constructors are used?

Showing Answers 1 - 5 of 5 Answers

pardeep dureja

  • Oct 9th, 2006
 

HiConstructor have no explicit return type implicitly constructor return initialized object. So in this situation void t3( ) is treated as a function not constructor.;-}0

Hi Friends,

      We use constructors to create and initialize objects. Evenif you don't create any constructor then the default constructor will create and initialize the object. Constructors have not any return type that is the major thing that makes it different from methods. Because you can create methods having classnames. In your problem you r doing the same you are creating a method having return type void and a constructor also.

                                                                        Abhishek(Sharad)

  Was this answer useful?  Yes

Raghava

  • Oct 20th, 2006
 

I got it

Thanks

  Was this answer useful?  Yes

chinnu

  • Nov 18th, 2006
 

Actually constructor means one type of special methods in java. It returns nothing even void also. These are used for intilising the objects with same parameters and different parameters.

  Was this answer useful?  Yes

constructor's don't have any return-type....... and hence when you precede void with constructor java comipler treats it as a METHOD of that class and not as constructor!!!

vinny

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions