What is the purpose of a parameterized constructor in Java?
- It initializes class-level variables with default values.
- It allows the creation of multiple instances of the same class.
- It accepts one or more arguments to initialize instance variables.
- It is used to create static objects.
In Java, a parameterized constructor is used to initialize instance variables with values provided as arguments during object creation. This allows objects to be created with different initial states. Option 1 is incorrect as the default constructor initializes class-level variables, not parameterized constructors. Options 2 and 4 are not accurate descriptions of parameterized constructors.
Loading...
Related Quiz
- Envision a scenario where you need to update a user’s details and also log the changes in an audit table. This operation needs to ensure data integrity and consistency. How would you achieve this using JDBC?
- How does Java differentiate between a constructor and a method?
- How does the behavior of CachedThreadPool differ from that of FixedThreadPool in terms of thread creation and task management?
- Which protocol is typically used to securely send data over the web?
- Lambda expressions are used primarily to define the implementation of ________ interfaces.