Hey folks,
Need your help:)
Wanted to understand the concept of method overloading and overriding in Java, as explained in Q.7 here.
How do we identify a problem, to which we can apply the above concept?
Hey folks,
Need your help:)
Wanted to understand the concept of method overloading and overriding in Java, as explained in Q.7 here.
How do we identify a problem, to which we can apply the above concept?
First, those are two completely different concepts.
Overloading is a convenience thing. Use it when you have a method that could be used with different paameters, eg an internet thing that could use an IPV4 or IPV6 address. You could have two methods with slightly differenet names, but the code will be clearer if you have the same name but different parameter types. It's also useful when you have some optional parameters, eg waitFor(something) and waitFor(something, timeout).
Overriding happens when you have a sublass that needs a different implementation of a method from its superclass. When that is needed its usually obvious.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.