문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top