Question-40: What is method overriding:
Answer:
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.
Question-41: Can we override static method?
Answer:
No, you can’t override the static method because they are the part of class not object.
Question-42: Why we cannot override static method?
Answer:
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.
Question-43: Can we override the overloaded method?
Answer:
Yes.
Question-44: Difference between method Overloading and Overriding.
Answer:
Question-45:Can you have virtual functions in Java?
Answer:
Yes, all functions in Java are virtual by default.
Question-46: What is covariant return type?
Answer:
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.
Answer:
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.
Question-41: Can we override static method?
Answer:
No, you can’t override the static method because they are the part of class not object.
Question-42: Why we cannot override static method?
Answer:
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.
Question-43: Can we override the overloaded method?
Answer:
Yes.
Question-44: Difference between method Overloading and Overriding.
Answer:
- 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.
- methodoverlaoding is occurs within the class. Method overriding occurs in two classes that have IS-A relationship.
- In this case, parameter must be different. In this case, parameter must be same.
Question-45:Can you have virtual functions in Java?
Answer:
Yes, all functions in Java are virtual by default.
Question-46: What is covariant return type?
Answer:
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.
No comments:
Post a Comment