0 votes
13 views
What are the differences between the constructors and methods?
in Education by (48.2k points)

1 Answer

0 votes

What are the differences between the constructors and methods?

There are many differences between constructors and methods. They are given below.

Java Constructor Java Method

A constructor is used to initialize the state of an object. A method is used to expose the behavior of an object.

A constructor must not have a return type. A method must have a return type.

The constructor is invoked implicitly. The method is invoked explicitly.

The Java compiler provides a default constructor if you don't have any constructor in a class. The method is not provided by the compiler in any case.

The constructor name must be same as the class name. The method name may or may not be same as class name.

by (48.2k points)

Related questions

0 votes
1 answer 9 views
9 views asked Nov 17, 2020 in Education by Editorial Staff (48.2k points)
0 votes
1 answer 10 views
10 views asked Nov 19, 2020 in Education by Editorial Staff (48.2k points)
0 votes
1 answer 11 views
0 votes
1 answer 11 views
0 votes
1 answer 23 views
23 views asked Dec 11, 2020 in Technology by JackTerrance (186k points)
0 votes
1 answer 12 views
0 votes
1 answer 14 views
0 votes
1 answer 9 views
0 votes
1 answer 10 views
0 votes
1 answer 9 views
0 votes
1 answer 13 views
0 votes
1 answer 24 views
0 votes
1 answer 21 views
0 votes
1 answer 16 views
0 votes
1 answer 19 views
0 votes
1 answer 8 views
0 votes
1 answer 9 views
...