java - Is this the case of method hiding? -
java - Is this the case of method hiding? -
i have next code in base of operations class employee have static method meth1() able phone call kid class (pro) object . case of method hiding or ? , not sure because haven't implemented meth1() method in pro class, still able phone call emplyee static method pro object.
class employee { string s; public string gets() { homecoming s; } public void sets(string s) { this.s = s; } protected static void meth1() { system.out.println("inside emp-meth1"); } } public class pro extends employee { /* * public void meth1() { system.out.println("inside encapsulation-meth1"); } */ public static void main(string as[]) { pro e = new pro(); // e.s ="jay"; e.meth1(); } }
output:
inside emp-meth1
thanks
jayendra
what trying hide? seek below code
emp.meth1()
phone call method based on reference not based on object beingness referred.
class employee { string s; public string gets() { homecoming s; } public void sets(string s) { this.s = s; } protected static void meth1() { system.out.println("inside emp-meth1"); } } public class pro extends employee { protected static void meth1() { system.out.println("inside encapsulation-meth1"); } public static void main(string as[]) { pro e = new pro(); employee emp = new pro(); emp.meth1(); //this case of method hiding e.meth1(); }
}
java override method-overriding method-hiding
Comments
Post a Comment