- 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
Does Java support default parameter values for a method?
Java does not support the concept of default parameter however, you can achieve this using
Method overloading
Using method overloading if you define method with no arguments along with parametrized methods. Then you can call a method with zero arguments.
Variable arguments
In Java methods parameters accept arguments with three dots. These are known as variable arguments. Once you use variable arguments as a parameter method, while calling you can pass as many number of arguments to this method (variable number of arguments) or, you can simply call this method without passing any arguments.
Example
public class Sample { void demoMethod(String... args) { for (String arg : args) { System.out.println(arg); } } public static void main(String args[] ) { new Sample().demoMethod("ram", "rahim", "robert"); new Sample().demoMethod("krishna", "kasyap"); new Sample().demoMethod(); } }
Output
ram rahim robert krishna kasyap
- Related Articles
- How to set default parameter values to a function in Python?
- How to set a default parameter value for a JavaScript function?
- Does java support hybrid inheritance?
- Does Java support multi-dimensional Arrays?
- Default array values in Java
- What is the syntax for passing Scanner object as a parameter in a method using java?
- Class declaration with a method that has a parameter in Java
- How to pass a lambda expression as a method parameter in Java?
- How does the keep parameter work in the pandas series.drop_duplicates() method?
- Pass long parameter to an overloaded method in Java
- Do local variables in Java have default values?
- Display default initial values of DataTypes in Java
- What are the default array values in Java?
- Default method vs static method in an interface in Java?
- Does Python support polymorphism?

Advertisements