Skip to content

Q 23 - Method & Constructor #27

Discussion options

You must be logged in to vote

Difference Between Method and Constructor

Feature Constructor Method
Purpose Used to initialize an object Used to define behavior or functionality
Name Same as the class name Can be any valid identifier (usually verb/action-like)
Return Type No return type (not even void) Must have a return type (can be void, int, String, etc.)
Invocation Automatically called when an object is created using new Manually called using the object
Default Behavior Java provides a default constructor if none is defined Java does not provide a default method
Overloading Can be overloaded (multiple constructors with different parameters) Can also be overloaded
Inheritance Not inherited by su…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HARSHITH-MV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants