06. Method Overloading and Overriding Questions

What is method overloading?

If a class have multiple methods by same name but different parameters, it is known as Method Overloading. It increases the readability of the program


Why method overloading is not possible by changing the return type in java?

Because of ambiguity


Can we overload main() method?

Yes, You can have many main() methods in a class by overloading the main method.


What is method overriding:

If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. It is used for runtime polymorphism and to provide the specific implementation of the method


Can we override static method?

No, you can't override the static method because they are the part of class not object


Can we override the overloaded method?

Yes.


Difference between method Overloading and Overriding.

               Method Overloading
                                 Method Overriding
1) Method overloading increases the readability of the program.
Method overriding provides the specific implementation of the method that is already provided by its super class.
2) method overlaoding is occurs within the class.
Method overriding occurs in two classes that have IS-A relationship.
3) In this case, parameter must be different.
In this case, parameter must be same.


What is covariant return type?

Now, since java5, it is possible to override any method by changing the return type if the return type of the subclass overriding method is subclass type. It is known as covariant return type


1 comment:

  1. top 10 salesforce institues in hyderabad which offers the best training in best salesforce training institute in which you can choose an institute for salesforce training as per your requirements and your interest in which it can either be online or offline

    ReplyDelete