Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can we declare a constructor inside a method in java?

user-image
Question added by Anand Kumar , Trainee , globysn Skills ,kolkata
Date Posted: 2013/11/16
Deleted user
by Deleted user

Y to add constructor. According to java when you declare a function or method, a constructor is automatically derived. So if u try to add it would be overloaded.

 

it shows error. So its not possible.

Abdul Majid Gaho
by Abdul Majid Gaho , Sr Java/Angular developer , Ministry Of Health - Oman

No, it is not possible.

HATIME ENHAS
by HATIME ENHAS , Ingénieur Etudes et Développement , Atos ITS Nearshore Centre Maroc

Yes you can create it if you have an inner class inside your method.

Shailender Kumar
by Shailender Kumar , Software Instructor , Markaz-E-Adab-O-Science

Yes u can create

More Questions Like This