Objects & Classes

6.How can you prevent object creation for a class while still allowing method calls?
  • A. By marking the class as final
  • B. By declaring all methods static
  • C. By using a private constructor and static methods
  • D. By throwing an exception in the constructor

By using a private constructor and static methods

By using a private constructor and static methods

7.How can you restrict object creation in Java?
  • A. By making the class abstract
  • B. By marking the constructor as private
  • C. By implementing an interface
  • D. By overriding the new operator

By marking the constructor as private

By marking the constructor as private