Frage

When a class is declared as final, is it possible to clone or serialize it's objects? Or is this impossible because final prevents the extending of subclasses, therefore preventing cloning and serialization from implemented?

War es hilfreich?

Lösung

Final for classes --> You can't extend the class. Final for objects --> You can't change the reference to the object.

Serializable/cloning--- > These concepts are for objects. You implement an interface to make the object of a perticular class Serializable/Cloneable.

So, yes, when a class is declared as Final, it is possible to Serialize/clone its objects provided you implement the necessary interfaces.

Andere Tipps

I think you may be not clear on some OOP concepts and their Java implementation.

You extend classes, while you serialize and clone objects.

There is a Singleton pattern that allows only a single object to be created, but that is a whole other story.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top