Reputation: 373
I found a question to implement a new kind of stack,in which they used different defined stack class but can we modify the predefined stack class methods in java rather than creating another class for that purpose?
Upvotes: 0
Views: 1113
Reputation: 6167
No, you cannot "modify" existing classes, just as you cannot modify methods of your own classes (other than by modifying their code directly).
You can, however, write your own class that extend
s predefined classes, and @Override
methods from the base class.
(Or you could, of course, copy & paste the source code of the internal classes into your own code and modfiy it, but why would you want to do that if you can just extend
)
Upvotes: 1