ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Can we declare a constructor inside a method in java?

user-image
تم إضافة السؤال من قبل Anand Kumar , Trainee , globysn Skills ,kolkata
تاريخ النشر: 2013/11/16
Advaitha Chidurala
من قبل Advaitha Chidurala , Teacher , Little Masters Abacus

You can only create a constructor with in a class whose name is same as the class name, you cannot definre it inside a method. 

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
من قبل Abdul Majid Gaho , Sr Java/Angular developer , Ministry Of Health - Oman

No, it is not possible.

HATIME ENHAS
من قبل 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
من قبل Shailender Kumar , Software Instructor , Markaz-E-Adab-O-Science

Yes u can create

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟