Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
What if we extend a normal class which has an abstract method, wouldn't it act as simple inheritance?

2 Answers

0 votes
by (11.3k points)

There are two rules to abstract methods and abstract classes:

  1. Even if there is one abstract method in a class, the class has to be defined as an abstract class.
  2. All abstract methods have to be implemented in the class that extends the abstract class. 

No, it will not act as simple inheritance because the point of abstract classes is providing a template set of methods to the classes that will implement them, but they aren't defined as in normal parent classes.  Simple inheritance would work if there is something set in the parent method to override, not when it is empty. 

0 votes
by (1.7k points)

If a normal class has an abstract method, it must have to declare the abstract itself. Extending it would then follow the protocols of inheritance, requiring the subclass to implement the abstract method, or the subclass must also be abstract. 

Without making it abstract, it would result in a compilation error.

1.4k questions

32.9k answers

507 comments

693 users

...