When we have method overriding, what is the use of having abstract methods?
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.
When we have method overriding, what is the use of having abstract methods?
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.
I am not convinced with ur answer
Abstract methods/classes leave detailed implementation to sub classes, and every sub classes may implement differently, thus leads to polymorphism in OOP.
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.