DEV Community

rajeshwari rajeshwari
rajeshwari rajeshwari

Posted on

Method overloading, defalt value..

Method overloading:

Method overloading in Java is a feature that allows a class to have multiple methods with the same name but different method signatures. The method signature consists of the method's name and its parameter list (number, type, and order of parameters). The return type of a method is not part of its signature and cannot be used to distinguish overloaded methods.
Rules for Method Overloading:

Same Method Name: All overloaded methods must share the same name within the same class.
Different Parameter List: The parameter lists of overloaded methods must differ in at least one of the following ways:
    Number of parameters: The methods can take a different count of parameters.
    Type of parameters: The methods can take parameters of different data types.
    Order of parameters: If the types are the same, their order can be different.
Enter fullscreen mode Exit fullscreen mode

Defalt value:

In Java, the concept of "default value" primarily applies to fields (instance variables and static variables) that are not explicitly initialized. Local variables, on the other hand, do not receive default values and must be explicitly initialized before use.
Default Values for Fields:
The Java compiler automatically assigns a reasonable default value to fields if they are declared but not explicitly initialized. These defaults depend on the data type:

Numeric Primitive Types (byte, short, int, long, float, double): The default value is 0 (or 0.0 for floating-point types).
boolean: The default value is false.
char: The default value is the null character '\u0000'.
Reference Types (Objects, Arrays): The default value is null.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)