Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top