August 2012

July 2012

May 2012

MethodOverrideRule

By | 2012-05-02T15:20:53+00:00 May 2nd, 2012|Learn By Example|

package com.override; public class MethodOverrideRule { public static void main(String args[]) { // Here reference type and Object type is same MethodOverrideRule scls = new MethodOverrideRule(); OverrideSubclass subcls = new OverrideSubclass(); // Here reference type is of Super class and Object is of child class MethodOverrideRule subOcls = new OverrideSubclass(); // This will invoke method [...]

MethodOverrideException

By | 2012-05-02T15:20:19+00:00 May 2nd, 2012|Learn By Example|

package com.override; import java.io.IOException; /* * Here will learn the impact of Exception on Overriding. */ class MethodOverrideException { public static void main(String args[]) throws Exception { // Here reference type and Object type is same MethodOverrideException scls = new MethodOverrideException(); // Here reference type is of Super class and Object is of child class [...]

MethodOverloadRule

By | 2012-05-02T15:17:32+00:00 May 2nd, 2012|Learn By Example|

package com.overloading; public class MethodOverloadRule { public static void main(String args[]) { MethodOverloadRule cls = new MethodOverloadRule(); //int i = cls.method(); System.out.println("Overloaded method without argument and int return type is called and return value is :"+cls.method()); cls.method("Hello"); } /* * Overloaded method with String argument and return type as void */ void method(String str) { [...]

MethodOverloadOtherClass

By | 2012-05-02T15:16:38+00:00 May 2nd, 2012|Learn By Example|

package com.overloading; /* * Here we will learn how to overload a method in subclass. */ public class MethodOverloadOtherClass { public static void main(String args[]) { MethodOverloadOtherClass cls = new MethodOverloadOtherClass(); /* * Super class can access only one method which it has declare in its * declaration */ cls.method(); subclass cls1 = new subclass(); [...]

MethodOverloading

By | 2012-05-02T15:16:08+00:00 May 2nd, 2012|Learn By Example|

package com.overloading; /* * Here we will learn how to overload a method in the same class. * Note: Which overloaded method is to invoke is depends on the argument passed to method. */ public class MethodOverloading { public static void main(String args[]) { //Creating object of the class MethodOverloading MethodOverloading cls = new MethodOverloading(); [...]

MethodOverloadException

By | 2012-05-02T15:15:41+00:00 May 2nd, 2012|Learn By Example|

package com.overloading; import java.io.IOException; /* * Here we will learn how exception declaration fit into method overloading and what is valid and what is not valid in case of * method overloading */ public class MethodOverloadException { public static void main(String args[]) { MethodOverloadException cls = new MethodOverloadException(); try { cls.method("Hello"); } catch (IOException e) [...]