Static Polymorphism: ==================== Method Overloading: =================== Q: ARE ANY BUILT-IN METHODS SUPPORTS THE METHOD OVERLOADING? ============================================================ Yes. Ex: subString() ==> to acquire the part of the string. Syntax: str.subString(begin_Index) Ex: "Java Programming".subString(4) ==> " Programming" str.subString(begin, end) Ex: "Java Programming".subString(0,4) ==> "Java" valueOf(): ========= valueOf(integer) valueOf(Float) ====================================================== Q: Guess whether the below code is correct in method overloading? ================================================================= class LoginModule{ public boolean login(String username, String password) { System.out.println("Login module is validating with username and password"); } public Boolean login(String email, String password) { System.out.println("Login module is validating with email and password"); } } ==> Method overloading is always based on: 1) Number of parameters 2) type of parameters 3) order of parameters ==> But in the above scenario, number of parameters, type of parameters and order of parameters are same. Hence we were not able to implement method overloading. ========================================================== Ex:-3: ====== class A{ void m1(int x, double y) { System.out.println("x = "+x); System.out.println("y = "+y); } void m1(double x, int y) { System.out.println("x = "+x); System.out.println("y = "+y); } } ==> Here, overloading is possible. Because of the order of parameters are changed. ======================================================= Ex_04: ====== class Directory { Employee met1(int eid) { // implementation } void met1(int eid) { // implementation } } In the above case, first method implementation can return the object of Employee class. second method implementation cannot return anything. ==> This is not the example for overloading, because method overloading cannot be based on return type. ======================================= Overloading for parent class method in child class: ==================================================== package Java.IO.AIT; class ClassA{ public static void m1(int x) { System.out.println("x = "+x); } } class ClassB extends ClassA{ public static void m1(int a, int b) { System.out.println("a = "+a); System.out.println("b = "+b); } } public class Main { public static void main(String[] args) { ClassB cb = new ClassB(); cb.m1(10); cb.m1(100,200); } } ==> yes, we can overload the parent class method in child class but the exception when the method is private type, we can't overload in child class. ================================================================ Q: Is static method overloaded? ================================ package Java.IO.AIT; class A{ public static void openFile(String filePath, String fileName) { System.out.println("File has Successfully opened."); } public static void openFile(String fileName) { System.out.println("File has Successfully opened."); } } public class ClassMain { public static void main(String[] args) { A aobj = new A(); aobj.openFile("C:\\Personal","abc.java"); aobj.openFile("abc.java"); } }