0

I have trouble understanding how an inherited method in a subclass from a superclass differs from a public method in a class which can be used in another class.

  • 3
    Different concepts. For the public modifier, see [What is the difference between public, protected, package-private and private in Java?](https://stackoverflow.com/q/215497/6395627). For inheritance, see https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html. – Slaw Apr 02 '20 at 17:43
  • long story short the concepts are orthogonal, a method can be at the same time public and inherited , alternatively private and inherited , or public non-inherited – Dr Phil Apr 02 '20 at 18:02
  • Does this answer your question? [What is the difference between public, protected, package-private and private in Java?](https://stackoverflow.com/questions/215497/what-is-the-difference-between-public-protected-package-private-and-private-in) – Michel Foucault Apr 02 '20 at 18:07
  • @Slaw I suggest you make an Answer of your Comment so this page can be marked as resolved. – Basil Bourque Apr 02 '20 at 19:22

1 Answers1

0

Please go through the basic OOP concepts, you will understand the difference. Very short answer could be that public methods you can just access where as using inheritance subclasses can modify existing behaviour.

Datta Diware
  • 602
  • 1
  • 5
  • 16