Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Abstract method vs overloading

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    114
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Abstract method vs overloading

    When we have method overriding, what is the use of having abstract methods?


  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Abstract method vs overloading

    Hi ,
    In the project implementation , it is dificult to verify the code whenever we use our own method names. That why,to usersatnd the code easyly the team leaders creat a some interfaces and declare some required abstract method in side interfaces withe meaningfull method names and fource to develpers create a classes which are subclass to provided interfaces. In this senario we are using method overriding to provide the implementains to abstract methods in implementation classes of interfaces.

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    114
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Abstract method vs overloading

    I am not convinced with ur answer

  4. #4

    Default Re: Abstract method vs overloading

    Abstract methods/classes leave detailed implementation to sub classes, and every sub classes may implement differently, thus leads to polymorphism in OOP.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Abstract method vs overloading

    Consider a base class shape. This class has an area method. How would you implement the area method? It's not really practical to do so, so you declare the method abstract and force extending classes to implement the area method.

    Could you make shape implement a "dummy" area method which did something like return 0? Yeah, but why? This leads to potentially erroneous results if another class, say Rectangle, doesn't override the area method. Now all of a sudden every Rectangle has area 0 and you're left with a runtime/logic error, the most difficult type of program error to debug. It may even go unnoticed and end up in the wild.

    It's a design choice to force extending classes to implement abstract methods. The end goal is to make programming easier, faster, and less buggy. If you force another programmer to implement the area method they're more likely do so up front (since the program won't compile without it). There's no guarantees that it will be implemented correctly, but at least one potential source of problems (missing overriding method) is not the culprit.

Similar Threads

  1. [SOLVED] Abstract method in a non-abstract class
    By bassie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 2nd, 2012, 11:27 AM
  2. Overloading Method
    By Tohtekcop in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 16th, 2012, 02:28 PM
  3. Advantages of method Overloading and Overriding
    By tcstcs in forum Java Theory & Questions
    Replies: 2
    Last Post: January 19th, 2012, 04:55 AM
  4. GUI error: is not abstract and does not override abstract method
    By djl1990 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 21st, 2011, 01:26 PM
  5. Method Overloading - Doubt
    By vidya lakshman in forum Java Theory & Questions
    Replies: 2
    Last Post: January 31st, 2011, 09:32 AM