Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Difference Between Constructor and Method in Java

Posted on 02/19/2025 By admin

Let’s start with very basic definitions of both Constructor and Methods in Java:-

A constructor of a class is used to initialize the object or instance of class using new keyword. It can be called as special method as it is different from normal methods. It differs from methods as a constructor should have same name as class name and should not have any return type.

A method is a set of code with name to perform specific actions whenever and wherever needed. A method can accept parameters and return value.

Now see the differences between Constructor and Method:-

  1. Constructor is used to initialize the object or instance of class whereas a method is used to perform specific task or functionality.
  2. Constructor must have same name as class name whereas a method can have any valid name. A method can have name same as class name with a return type.
  3. Constructor must have no return type (Not even void) in declaration whereas a method should have a return type (Including void) in declaration.
  4. A constructor can be called explicitly (Parameterized constructor) or implicitly ( No arg constructor) whereas a method needs to be called explicitly always.
  5. If a class does not have any constructor, a default constructor is provided. There is no default method concept. You need to create it explicitly.
  6. Constructors are not inherited while non-static methods are inherited.
  7. Constructors cannot be overridden whereas methods can be overridden.
  8. A constructor can be called using new keyword whereas method can be called using object (Non static methods ) or class reference ( Static methods) or by name ( Calling Non static method in another non static method and Calling static method in another static method ).
  9. A constructor can call another constructor using this() or super() whereas a method can call other method directly or using class or object reference.
  10. A constructor cannot be static, abstract , final, native or synchronized whereas a method can be.
  11. A constructor can bring method (Non-static) in existence/memory.

#ThanksForReading

Uncategorized

Post navigation

Previous Post: Frequently Asked Java Program 10: Draw An Equilateral Triangle Using Stars Of Given Row
Next Post: TestNG Tutorials 17: Can @Test Annotation Be Used For A Class In TestNG?

Related Posts

image – Make Selenium Easy Uncategorized
GIT Tutorials – End To End Archives – Page 2 of 3 – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
October 2, 2019 – Make Selenium Easy Uncategorized
Frequently Asked Java Program 23: Java Program to Remove Extra WhiteSpace Between Words In Given String | Make Selenium Easy Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark