1.

What Are The Rules In Defining A Constructor?

Answer»
  • Constructor name should be same as class name.
  • It should not contain RETURN type.

It should not contain Non Access Modifiers:

  • final ,static, abstract, synchronized
  • In it logic return statement with value is not allowed.

It can have all four accessibility modifiers:

It can have throws CLAUSE:

  • we can throw exception from constructor.
  • It can have logic, as part of logic it can have all java legal statement EXCEPT return statement with value.
  • We can not place return in constructor.

It should not contain Non Access Modifiers:

It can have all four accessibility modifiers:

It can have throws clause:



Discussion

No Comment Found