Difference between overloading and Overriding. <Giving a
confusing example to test the concept.>
(also asked in PA Consultancy Group,iflex,Value
chain,IBM,CTS,Accenture, Tarang>
Answers were Sorted based on User's Feedback
Answer / ketan shekhawat
Overloading and Overiding are pratical implementation of OOPs Concept.
Overloading:
In Simple words, Same function name but different signature(Parameters)
For Example:
To Add 2 integers Add(int i, int j)
To add two string Add(string i, string j)
Depending on the signature(parameters) of the calling function, respective function would be called. if you pass 2 string parameter second function would be called and if you pass two integer parameter first function would be called.
Overriding(Polyphormism):
Same Function Name, same signature, different functionality.
Example for overriding
Class Shapes { Virtual void Paint() }
Class Circle:Shapes { Override void Paint() }
Class Square:Shapes { Override void Paint() }
Here in the above code we can see that the shapes is class which has a method Paint, which would paint according to the shape of the object each object would implement the paint method differently based on its dimensions.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ganga
using same methodname with different signatures is known as
overloading where as
changing the definition of the parentclass in chidclass is
known as overridding.
| Is This Answer Correct ? | 7 Yes | 9 No |
How transient variable is different from volatile variable?
84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query(”GET INFO FROM CUSTOMER”); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? 1 Line 92 will not execute. 2 The connection will not be retrieved in line 85. 3 The resource connection will not be closed on line 88. 4 The enclosing method will throw an exception to its caller.
What is thread life cycle in java?
Why singleton class is used in java?
Difference between final and effectively final ?
What is the syntax and characteristics of a lambda expression?
What does @param args mean in java?
What do you mean by append?
What is preparedstatement in java?
What is the difference between a method and a procedure?
Can singleton class be serialized?
Is node a data type in java?