Question

For Java: What is the key difference between abstract classes and regular classes? What does this...

For Java:

What is the key difference between abstract classes and regular classes? What does this difference prevent you from doing with abstract classes and how does polymorphism help bypass this restriction?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In Java, the key difference between abstract classes and regular classes is:
Regular classes:

The regular classes can be instantiated as they provide or inherit the implementation for all of their methods.

Abstract classes:
The simple and obvious difference being, its header contains the "abstract" reserved keyword that is used to create an abstract class or ew instances of an abstract class. It is impossible for using the new operator for constructing objects from them directly.
They "cannot be instantiated, however, can be subclassed", as at least one method is not implemented. They are supposed to be extended. There is a benefit of using them as compared to using regular classes. They are used when there is a requirement for enforcing base functions and have base properties. Making the class abstract avoids that incomplete class to be created accidentally. Using abstract classes forces the core functionality to be implemented by the siblings.

What this difference prevents us from doing with abstract classes:
Since abstract classes cannot be instantiated, it prevents you from creating an object of it. It prevents you from creating objects of an abstract class.s

How polymorphism helps bypass this restriction:
In case, the abstract class is extended by any other class, through inheritance, the child gets all the methods. With this, it achieves dynamic polymorphism, using a reference of the parent. It is possible to call that concrete method of the parent class. In case, you do need the parent method, that concrete method of the parent class can just be overridden in child class. Hence, an abstract class can be used in polymorphism. Polymorphism thus is achieved by a subclass extending an abstract class providing its own implementation for these abstract methods.

Add a comment
Know the answer?
Add Answer to:
For Java: What is the key difference between abstract classes and regular classes? What does this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT