- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is a constructor in Java?
Constructors are similar to methods but,
- They do not have any return type.
- The name of the constructor is same as the name of the class.
- Every class has a constructor. If we do not explicitly write a constructor for a class, the Java compiler builds a default constructor for that class.
- Each time a new object is created, at least one constructor will be invoked.
- A class can have more than one constructor.
Example
public class Puppy { public Puppy() { } public Puppy(String name) { // This constructor has one parameter, name. } }
- Related Articles
- What is constructor overloading in Java?
- What is constructor chaining in Java?
- What is the purpose of a constructor in java?
- What is the purpose of a default constructor in Java?
- What is the super() construct of a constructor in Java?
- What is the return type of a Constructor in Java?
- What is the use of constructor in Java?
- Is constructor inherited in Java?
- What is the purpose of private constructor in Java?
- What is the use of parametrized constructor in Java?
- Java constructor return a value but, what?
- What is a copy constructor in C#?
- What is a static constructor in C#?
- What is a constructor method in JavaScript?
- What is a default constructor in JavaScript?

Advertisements