Question Bank (Term 2)
Subject – Computer Applications
Class X
CONSTRUCTOR
1. Choose the correct answer.
1) Which unit of a class gets called when the object of the class is
created?
i) function
ii) constructor
iii) access specifier
iv) instance variable
2) What is constructor in Java?
i) It is an object
ii) It is a recursive block of code
iii) It is a block of code like method
iv) An instance variable
3) The default constructor is used for
i) Calling default method
ii) Initializing default values to instance variables
iii) Differencing default objects
iv) Calling static method
4) What is true about constructor
i) It must have return type.
ii) It can take any number of parameters
iii) It has name other than class name
iv) Constructor cannot accept any parameter
5) If constructors are overloaded, what differentiates it?
i) Parameter list
ii) Return type
iii) Both a and b
iv) None of these
6) Among the following Statements, which are true about Constructors?
(I) a new operator automatically calls them.
(II) they cannot be private
(III) they cannot be virtual
i) I & III
ii) I & II
iii) II & III
iv) All of the above
7) Default constructor requires how many parameters?
(i) 3
(ii) 0
(iii) 2
(iv) 1
2. Predict the output of the following program:
class T
{
int t = 20; T()
{
t = 40;
}
public static void main(String args[])
{
T t1 = new T();
[Link](t1.t);
}
}
3. Consider the program given below and answer the given questions.
class academic
{
int x,y;
void access()
{
int a,b;
academic student=new academic();
[Link](Object Created”);
}
}
Now answer the following questions based on the above program.
a. What is the object name of the class?
b. Name the instance variables used in the class.
c. Write the name of local variables used in the program.
d. Give the type of function being used and its name.
4. Read the following text and choose the correct answer:
Java constructor overloading is a technique in which a class can have any
number of constructors that differ in parameter list. The compiler
differentiates these constructors by taking into account the number of
parameters in the list and their type.
Why do we use constructor overloading?
To use different types of constructors.
Because it's a feature provided.
To initialise the object in different ways.
To differentiate one constructor from another.
5. Define a class SalaryCalculation described as below:
Data members:
name (String data type)
basicPay, specialAlw, conveyanceAlw, gross, pf, netSalary, annualSal
(double data types)
Member methods:
SalaryCalculation(): A constructor to assign name of employee
(name), basic salary (basicPay) of your choice
and conveyance allowance (conveyanceAlw) as
Rs. 1000.00.
void salaryCal() : To calculate other allowances and salaries as
given below:
specialAlw = 25% of basic salary
pf = 11% of basic salary
gross = basicPay + specialAlw + conveyanceAlw
netSalary = gross – pf
annualSal = 12 months of net salary
void display() : To display the name and other calculations with
suitable headings.
Write a main() method to create object of the class and call the required
member methods.
6. Define a class BankAccount with following details:
Data members:
String name – to store name of the customer.
long accno – to store the account number.
double bal – to store the account balance.
Member methods:
BankAccount() – default constructor
BankAccount(String n, long accnumber, double b) – parameterized
constructor
void deposit(double amt) – deposits the amount to the account and displays
the amount deposited as well as the final balance.
void withdraw(double amt) – displays amount to be withdrawn, deletes the
amount from balance if sufficient balance is available and displays the final
balance otherwise displays the message “Insufficient Balance”.
void display() – Displays the name, account number and final balance.
Write a main() method to create object of the class and call the required
member methods.
****************