Can Nosotros Overload Static Method Inwards Coffee Programme - Example

Overloading static method In Java
Yes, nosotros tin post away overload static method inwards Java. In damage of method overloading static method are only similar normal methods together with inwards gild to overload static method you lot involve to supply approximately other static method amongst same advert but dissimilar method signature. Static overloaded method are resolved using Static Binding during compile time. Overloading method inwards Java is completely dissimilar than overriding method together with equally discussed inwards our final article nosotros can non override static method inwards Java but nosotros tin post away sure overload static method inwards Java. Here is an instance which confirms that we tin post away overload static method inwards Java:

 

Overloading Static method inwards Java - example

 static method are only similar normal methods together with inwards gild to overload  Can nosotros overload static method inwards Java Program - ExampleIn this instance nosotros cause got a static method called greet(String name) which takes a String declaration equally advert together with impress a default greeting message equally "Hello John". Now to demo that nosotros tin post away overload static method inwards Java I cause got provided approximately other static method amongst same advert but dissimilar method signature which non alone takes advert of somebody to greet but besides greeting message e.g. Good Morning, Good Evening etc.

/**   
 * Java programme to demo that nosotros tin post away overload static method inwards Java.
 */

public class StaticOverloadingTest {
 
    public static void main(String args[]) {
        greet("John"); //will telephone phone static method amongst i String argument
        greet("John", "Good Morning"); //overloaded static method volition survive telephone phone    

    }
 
    /*
     * static method which volition survive overloaded
     */

    public static void greet(String name){
        System.out.println("Hello " + name);
    }
 
    /*
     * Another static method which overload inwards a higher house Hello method
     * This shows that nosotros tin post away overload static method inwards Java
     */

    public static void greet(String name, String greeting){
        System.out.println(greeting + " " + name);
    }


}
Output
Hello John
Good Morning John


That's all on How tin post away nosotros overload static method inwards Java. In summary, Don't confuse betwixt method overloading together with method overriding. In short, you lot tin post away overload static method inwards Java but you lot tin post away non override static method inwards Java.



Other Java OOPS tutorial from JDK67


Further Learning
SOLID Principles of Object Oriented Design
Absolute Introduction to Object Oriented Programming inwards Java
Java - Object Oriented Programming [For Absolute Beginners]

0 Response to "Can Nosotros Overload Static Method Inwards Coffee Programme - Example"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel