- 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
How to declare a constructor in Java?
While declaring the constructors you should keep the following points in mind.
- A constructor does not have a return type.
- The name of the constructor is same as the name of the class.
- A class can have more than one constructor.
Example
public class Sample { int num; public Sample() { num = 30; } public Sample(int value) { num = value; } }
- Related Articles
- Can we declare a constructor as private in Java?
- Can we declare constructor as final in java?
- What happens when you declare a method/constructor final in Java?
- How to declare a class in Java?
- How to call the constructor of a superclass from a constructor in java?
- How to declare a local variable in Java?
- How to create a parameterized constructor in Java?
- How to create a default constructor in Java?
- How to declare a static String array in Java
- How to call Private Constructor in Java
- How to declare, define and call a method in Java?
- How to declare a variable within lambda expression in Java?
- How to declare an Array Variables in Java?
- How to write/declare an interface inside a class in Java?
- How to create a constructor reference for an array in Java?

Advertisements