- 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
Constructor overloading in Java
Yes! Java supports constructor overloading. In constructor loading, we create multiple constructors with the same name but with different parameters types or with different no of parameters.
Example
public class Tester { private String message; public Tester(){ message = "Hello World!"; } public Tester(String message){ this.message = message; } public String getMessage(){ return message ; } public void setMessage(String message){ this.message = message; } public static void main(String[] args) { Tester tester = new Tester(); System.out.println(tester.getMessage()); Tester tester1 = new Tester("Welcome"); System.out.println(tester1.getMessage()); } }
Output
Hello World! Welcome
- Related Articles
- Constructor Overloading In Java programming
- Constructor overloading in enumerations in Java.
- What is constructor overloading in Java?
- Constructor Overloading in C#
- Constructor Overloading in C++
- Overloading in java programming
- Method overloading in Java
- Using Method Overloading in Java
- Overloading Varargs Methods in Java
- What is Overloading in Java?
- Enum constructor in Java
- Default constructor in Java
- What is method overloading in Java?
- Java default constructor
- Java parameterized constructor

Advertisements