- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 constructor overloading in Java?
Similar to methods you can also overload constructors i.e. you can write more than constructor with different parameters.
And, based on the parameters we pass at the time of instantiation, respective constructor will be invoked.
Example
public class Sample { public Sample() { System.out.println("Hello how are you"); } public Sample(String data) { System.out.println(data); } public static void main(String args[]){ Sample obj = new Sample("Tutorialspoint"); } }
Output
Tutorialspoint
Advertisements