If you are within your first year of application development in Java you may have asked yourself this question. I know I did.
What is the difference?
Here is a reference list that I have compiled for your convenience.
Download the excel file and build upon other comparisons you need to keep track of –>constructor-vsmethods.xlsx
Topic |
Constructors |
Methods |
Purpose |
Create an instance of a class – Object Initialization | Grouped Java statements – Each performs a small unit or task |
Modifiers |
No – Cannot be abstract, final, native, static, or synchronized, already marked as final & static. | Yes – Can be abstract, final, native, static, or synchronized |
Has a Return type |
No – not even void | Yes – void or a valid return type |
Naming Convention |
Same name as the class, first letter is capitalized by convention) — usually a noun | Any name except the class. Method names begin with a lowercase letter by convention — usually the name of an action |
Inheritance |
No – Constructors are not inherited | Yes – Methods are inherited |
Compiler automatically supplies a default constructor |
If the class has no constructor, a no-argument constructor is automatically supplied | Does not apply |
Compiler automatically supplies a default call to the super-class constructor |
If the constructor makes no zero-or-more argument calls to super, a no-argument call to super is made | Does not apply |
Can be Overloaded/Overwritten? |
Yes | Yes |
Can be public, protected, private? |
Yes | Yes |
Must be same name as Class? |
Yes | No, arbitrary |
chained and they are called in a particular order |
Yes | No |