Pergunta de entrevista da empresa Tudip Technologies

Can we write try catch inside constructor?? Binary Search

Respostas da entrevista

Sigiloso

12 de nov. de 2016

Yes we can write try catch block in constructor and it does work properly. class a { a() { try { int b=5/0; }catch(Exception e) { System.out.println(e); } } output : java.lang.ArithmeticException: / by zero public static void main(String args[]) { a a1=new a(); } }

10

Sigiloso

28 de nov. de 2017

yes why not we can write try catch block in a constructor and it works perfectly

Sigiloso

2 de jul. de 2018

Yes, we can write

Sigiloso

5 de abr. de 2017

Yes, we can write try catch and finally block in a constructor ant it works properly.

Sigiloso

14 de out. de 2016

No we can not. Constructor is only for initialization of fields.

1