Basic Java Interview Questions and Answers - 3
13. Significance of Super keyword.
- It is used to access the methods of a parent class.
- It is a non-static method and cannot be used inside main method in Java.
- It invokes the constructor of the parent class.
- The Outer.super can be used to get current instance of an outer class and its parent in Java.14. How objects are stored in Java?
In java, each object gets a memory space from a heap. When an object is destroyed by a garbage collector, the space allocated to it from the heap is re-allocated to the heap and becomes available for any new objects.15. What is Polymorphism in Java? What are the kinds of Polymorphism?
Polymorphism means the ability to take more than one form. It is the capability of an action or method to do different things based on the object acting upon.
Two types of Polymorphism:
1. Method Polymorphism through overloading
2. Object Polymorphism by inheritance and interface16. What is method overloading?
Method overloading allows us to create multiple methods with the same name but different signature.
We used Method overloading when a couple of methods are needed with conceptually similar functionality with different parameters.
We can achieve method overloading in two ways:
By changing the number of arguments
By changing the return type17. Can main() method in Java return any data?
In java, main() method is always declared with a void return type, so it can't return any data18. Is it poosible to pass argument to a function by reference instead of pass by value in Java?
No, we can pass argument to a function only by value and not by reference in Java