Computer Applications
Assertion (A): The default constructor initializes object fields to zero or null depending on their data type.
Reason (R): Java constructors are inherently tied to the initialization of an object and therefore do not specify a return type.
Answer
Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
Explanation
- Assertion (A): The default constructor initializes fields to their default values (e.g.,
0
for numbers,null
for objects,false
for boolean). - Reason (R): Constructors are used for object initialization and do not have a return type.
- The Reason explains why the default constructor initializes fields automatically.
Related Questions
State whether the following statement is True or False :
Every class must have all types of constructors.
Fill in the blanks:
The _________ refers to the current object.
What is meant by a constructor?
The basic salary of employees is undergoing a revision. Define a class called Grade_Revision with the following specifications:
Data Members Purpose String name to store name of the employee int bas to store basic salary int expn to consider the length of service as an experience double inc to store increment double nbas to store new basic salary (basic + increment) Member Methods Purpose Grade_Revision() constructor to initialize all data members void accept() to input name, basic and experience void increment() to calculate increment based on experience as per the table given below void display() to print all the details of an employee Experience Increment Up to 3 years ₹1,000 + 10% of basic 3 years or more and up to 5 years ₹3,000 + 12% of basic 5 years or more and up to 10 years ₹5,000 + 15% of basic 10 years or more ₹8,000 + 20% of basic Write the main method to create an object of the class and call all the member methods.