Page 326 - CA_Blue( J )_Class10
P. 326
void pattern2() : Prints the following pattern:
1
35
7911
…
10. A computerised bus charges fare from each passenger based on the distance travelled as per the tariff given below:
Distance in Km Rate per Km
First 10 km Rs. 5
Next 20 km Rs. 7.5
Next 10 km Rs. 10
Above 50 km Rs. 15
Design a class with the following specifications to solve the above problem:
Class name : fare
Data Members
int dis : Distance travelled
double bill : Stores the bill amount
Methods
fare() : Constructor to initialize
fare(int d) : Initializes dis with d
void calculate() : Calculates the total bill amount on the above criteria.
void display() : Print the data members.
Previous Years' Questions
SECTION A
1. Java compiler automatically creates a default constructor in case no constructor is present in the java class. [2022]
a. True b. False
Ans. a.
2. The concept of having more than one constructor with different types of parameters:
a. Copy constructor b. Method overloading
c. Constructor overloading d. Overloaded methods
Ans. c.
2. Write two characteristics of a constructor. [2018]
Ans. The characteristics of a constructor are:
(i) Name of the class and the constructor’s name is same.
(ii) They have no return type.
(iii) They are always public.
(iv) They are used to initialize the object.
(v) They cannot be called separately unlike other methods.
3. Differentiate between constructor and method. [2017]
Ans.
Constructor Method
1. It is used to initialize the instance variables of the 1. It is used to execute the Java code which perform a specific
object job.
2. It does not have a return type. 2. It always have a return type.
4. What is a parameterised constructor? [2016]
Ans. A parameterised constructor is type of constructor with parameters. Number of parameters may be different depending on the
number of instance variables.
5. Name the two types of constructors. [2015]
Ans. The two types of constructors are parameterised constructors and non-parameterised constructors.
324324 Touchpad Computer Applications-X

