Stack
is not a Vector
then why Stack class is extending(is a relationship) Vector class in JDK, Stack suppose to work with push()
& pop()
operations, but because it extends Vector I am able to do add()
and remove()
operations over a stack.
I think rather extending Vector class, Stack class should use Vector class as a composition.
Outmoded classes
Both Stack
and Vector
were included with the first release of Java. Java was rushed to market ahead of its time because of the Internet frenzy at that time.
Some of the classes bundled with those earliest versions of Java, such as the date-time classes, were not well thought-out. They had not been subjected to peer review and public scrutiny as were later libraries such as some produced through the JAva Community Process and through open-source projects and industry consortium projects.
Java Collections framework
The Java Collections framework supplants both of these classes. Similarly, the java.time framework supplants the old date-time classes such as java.util.Date
/.Calendar
. The old classes remain in Java for backwards compatibility with existing apps but should not be used in new code.
The Stack
class documentation tells you this, clearly saying you should instead be using an implementation of the Deque
interface.