Wednesday, May 7, 2014

Method Overloading: Variable number of Arguments

One of the rules of method overloading is different number of arguments in the overloaded method definitions
Consider
public void printInt(int a)
public void printInt(int a, int b)
public void printInt(int a, int b, int c)
public void printInt(int...x) /*Ah! tricky one*/
All above methods are overloaded. But what will be the output for this code?
printInt(1,2,3);

Saturday, April 19, 2014

BaseClass-ChildClass Reference-Object Cases

1. BaseClass reference with BaseClass object

BaseClass bc1 = new BaseClass();
bc1.commonMethod();
BaseClass reference here has access to all the public methods and instance variables of BaseClass. So calling commonMethod will in return result in calling commonMethod of BaseClass.
Output:
Executing method of Base class