Signature differences
Constructors and methods differ in three aspects of the signature: modifiers, return type, and name. Like methods, constructors can have any of the access modifiers: public, protected, private, or none (often called package or friendly). Unlike methods, constructors can take only access modifiers. Therefore, constructors cannot be
abstract, final, native, static, or synchronized.
The return types are very different too. Methods can have any valid return type, or no return type, in which case the return type is given as
void. Constructors have no return type, not even void.
No comments:
Post a Comment