aspose file tools*
The moose likes Beginning Java and the fly likes Overriding and OverLoading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Overriding and OverLoading" Watch "Overriding and OverLoading" New topic
Author

Overriding and OverLoading

Suri Babs
Ranch Hand

Joined: Mar 27, 2003
Posts: 50
1.Why we need overridding and overloading?
2. These are bad according to me, since these process will happen at run time, i mean late-binding. And this is a performance issue.

Could any satisfy me about these questions.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
Actually, Overloading occurs at compile-time, so there is no real issue there. (See here for an example)
While it is true that over-riding does create a performance issue, so does the rest of Object-Oriented Programming. Thankfully, machines are fast enough these days (and the languages optimized enough) that the hit to performance is not noticed. While it is true that you could write an extremely fast program in C, development and maintenance of said program would be extremely difficult. Programs today do so much more than their predecessors of a decade ago that not using an OO-language is a major drawback (ever look at the souce code for a large PERL program? They are difficult to get through.)
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Suri
"Overriding" gives a class an easy way to intercept messages before they get to its superclass.As you know, most OOP languages implement overriding based on the run-time class of objects. In C++, run-time overriding is an option invoked with the "virtual" keyword.
"Overloaded method" can give you convenient to write you programme,the best way for me is that it groups the relevent method into the same name, do not need to write a new method with differ name if the method just contains different parameter lists.
The following is a example
PrintWriter object is used to do output some text to a file.It has many methods, I use some methods to illustrate what I want to say:
void print(String s)
void print(int i)
void print(long l)
void print(float f)
Now,you only need to know what data type you want to put it to a text file.
I know it would confuse some beginner,but after you master this concept,you may like it.


Francis Siu
SCJP, MCDBA
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
These are bad according to me, since these process will happen at run time, i mean late-binding.
The current programming paradigm is "Write clear code that is easy to understand, extend, and maintain, and resist the temptation to optimize."
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Programming is loaded with comprimises and balancing acts. In this case, it is the question of maintenance vs. performance. Many such conflicts exist and you have to understand the pros and cons of different approaches in order to decide what approach is best for a given problem. With polymorphism and overriding, the pay off is in maintenence and code re-use. As you mentioned, the cost is some performance overhead for late-binding. I don't view this as bad. It's simply a trade-off.


Java API Documentation
The Java Tutorial
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Being an old curmudgeon, I remember the early days of C vs C++ on PCs and the argument that late binding would never perform. Not only was there dynamic lookup, but in jumping between classes to execute methods you were more likely to execute long jumps than short jumps (oh the agony!) and (after the PC got virtual memory) more likely to cause page faults. There were regular articles excitedly describing how various compiler vendors were tweaking their VTables.
Now hardware is fast enough we tend to forget all that stuff, except maybe keep your inheritance tree wider than deep.
But to repeat a conclusion from above: Write source code for humans to read. Don't compromise readability for what the compiler or JVM might do!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding and OverLoading
 
Similar Threads
method overriding
polymorphism
Overriding/overloading
Overriding,Overloading methods
Polymorphism