Interview questions on method overloading
Overloading
- What is method overloading?
In a class,
Overloaded Method having same name but different parameters or Overloaded methods will have same name but different number of arguments or different types of arguments.
- Can we declare one overloaded method as static and another one as non-static?
Yes. Overloaded methods can be either static or non static.
- Is it possible to have two methods in a single class with same method signature but different return types?
No compiler will give duplicate method error
- Can we overload main method ?
Yes, we can overload main() method. A class can have any number of main() methods but execution starts from public static void main(String[] args) only.
Comments
Post a Comment