0

Parent Class Method name -> calculateTax Since Child Method name -> calculateTax

class will inherit this method I still want to call parent class calculateTax method

Child ch = new Child() ch.calculatetax() -> this should call parent class method , how can this be achieved

1
  • If you don't have any other logic in your child class's calculateTax(), then think about removing it completely. If you use some data returned from parent, then you could use the super keyword Commented Aug 24, 2015 at 9:28

1 Answer 1

2

This is not possible, in your case since you are calling calculateTax method with the object of Child class. The method of child class will override the calculateTax of parent class.

But you can call the parent class method by using super keyword inside the child method body like:-

super.calculateTax ();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.