What are the differences between the constructors and methods?


  • A constructor is used to initialize the state of an object.
  • A constructor is invoked implicitly.
  • A constructor must not have a return type.
  • The Java compiler provides a default constructor if you don't have any constructor in a class.
  • The constructor name must be same as the class name.


  • A method is used to expose the behavior of an object.
  • A method must have a return type.
  • The method is invoked explicitly.
  • The method is not provided by the compiler in any case.
  • The method name may or may not be same as class name.

Java Concepts OOP •  Added 10 months ago

why is string is immutable in java?

* In Java, string objects are immutable in nature which simply means once the String object is created its state cannot be modified. * Whenever you ...

What is the difference between this() and super() in Java?

In Java, super() and this(), both are special keywords that are used to call the constructor. __this:__ 1. this() represents the current instan ...

What is meant by Object Oriented Programming

Object-Oriented Programming or OOPs is a programming style which focuses on the below core features: * __Inheritance__ : Inheritance is a process ...

What is the difference between equals() and == in Java?

* __Equals()__ method is defined in Object class in Java and used for checking equality of two objects defined by business logic. * __''==''__ or dou ...

What is final keyword in Java?

__final__ is a special keyword in Java that is used as a non-access modifier. A final variable can be used in different contexts such as final variabl ...

We use cookies to provide you with a great user experience, analyze traffic and serve targeted promotions.   Learn More   Accept