What happens if no constructor is provided in a Java class?
- The class cannot be instantiated, and objects of that class cannot be created.
- Java automatically provides a default no-argument constructor for the class.
- The class can only be instantiated by other classes in the same package.
- The class becomes a singleton by default.
a) is correct. If no constructor is provided in a Java class, Java automatically provides a default no-argument constructor. b) is a common misconception; Java only provides a default constructor if you haven't defined any constructors explicitly. c) and d) are incorrect statements.
Loading...
Related Quiz
- You are developing a real-time gaming application where certain operations need to be repeated at regular time intervals. Which looping mechanism and timing control statements would you use to achieve this without blocking the user interface?
- What happens to the result of a relational operation if both operands are NaN?
- Which of the following is a primitive data type in Java?
- How does Binary Search perform when there are multiple occurrences of the search key in the data?
- What method is commonly used to execute SQL queries in Java?