How would you design a class that shouldn’t be instantiated?

  • By declaring the class as abstract.
  • By defining a private constructor.
  • By making the class private.
  • By using the final keyword.
To prevent a class from being instantiated, you can define a private constructor. When the constructor is private, it cannot be called from outside the class, effectively preventing object creation.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *