Các câu hỏi phỏng vấn và câu trả lời về phần "Core Java - OOPs concepts: Initial OOPs" - Phần 4: Method Overloading và Method Overriding
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
Becauseof ambiguity
Yes, You can have many main() methods in a class by overloading the main method.
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.
No, you can't override the static method because they are the part of class not object.
It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap.
Yes.
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. |
Yes, all functions in Java are virtual by default.
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.
Nguyễn Thị Bảo Trang
» Tin mới nhất:
» Các tin khác: