In Inheritence is there no need of all the methods in parent class should be implemented in child class as abstract | Core Java Forum
H
Harika Posted on 28/07/2023

while i'm doing abstarct method i find that all the methods should be implemented in child class like wise in inheritence is there no need to implement all the methods in parent class  to child class?

then what is inherited in inheritence method means by using inheritence what we are in heriting from parent class to child class

 


Y
Yogesh Chawla Replied on 29/07/2023

While i'm doing abstract method, i find that all the methods should be implemented in child class

No, when we extend abstract class in any child class, only those methods need to be defined in child class which are marked as abstract in parent abstract class. This is how we enforce unique functionality so that each and every individual child class which is extending abstract class should define their own implementation of parent class abstract method. It isn't the case that we define all methods of parent abstract class in child class. We define only those methods in child class which are marked as abstract in parent class and other non-abstract methods, we can use it straight away using child class object or using parent class object.

 

likewise in inheritance is there no need to implement all the methods in parent class to child class?

Yes, when we extend any class in java, it is not mandatory that we have to override one method or more than one method in child class. We can use parent class method definition also using child class object in child class itself. There is no rule as such that we have to define any method in child class in case of inheritance.

 

then what is inherited in inheritance method means by using inheritance what we are inheriting from parent class to child class

 

Yes, we can inherit all or one or no method in child class, that is our choice but basically when we implement the concept of inheritance, we are interested in parent class methods. We can use parent class methods as such or we can override and give new definition to those methods, that is completely our choice.