As we know Java is an object oriented language. Everything is objects in Java. We also know that objects have something (instance variables / fields) and do something (methods).
Can we say Contructors are Methods in Java?
If you're new to Java and trying to grasp the concept for the first time, you can think of constructors as factory methods. (Like in Python for instance where a constructor just a method called __init__
.) You should however move on quickly and understand that there are many differences. To name a few:
this
reference.new
, and has a special bytecode, invokespecial
, while instance methods are called by obj.method()
which typically compiles to the invokevirtual
bytecode.