Constructors
6.What happens if a class has multiple constructors and none have the this () keyword?
-
A. The compiler adds this () automatically.
-
B. The default constructor is ignored.
-
C. Each constructor executes independently without chaining.
-
D. The object cannot be instantiated.
Each constructor executes independently without chaining.
Each constructor executes independently without chaining.
7.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
8.If a class contains only a private constructor, how can objects of that class be created?
-
A. By making the constructor public
-
B. By using a factory method inside the class
-
C. By inheriting the class and accessing the constructor
-
D. Objects cannot be created
By using a factory method inside the class
By using a factory method inside the class