sarpit23
sarpit23

Reputation: 373

can we modify the predefined methods of classes in java?

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

Answers (1)

Johannes H.
Johannes H.

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 extends 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

Related Questions