Page 293 - CA_Blue( J )_Class10
P. 293
9. Name the Java keyword that: [2013]
(i) indicates that a method has no return type. (ii) stores the address of the currently calling object.
Ans. (i) void (ii) this
10. Write a Java statement to create an object mp4 of class Digital. [2013]
Ans. Digital mp4 = new Digital();
11. What does a class encapsulate? [2013]
Ans. A class encapsulates data and behaviour.
12. Differentiate between public and private modifiers for members of a class. [2012]
Ans. The public modifier makes both members (data and methods) accessible from anywhere.
The private modifier makes the members (data and methods) accessible only within the class.
13. In the program given below, state the name and the value of the: [2012]
(i) method argument or argument variable (ii) class variable
(iii) local variable
class MyClass{
static int x = 7;
int y = 2;
public static void main(String args[]){
MyClass obj = new MyClass();
System.out.println(x);
obj.sampleMethod(5);
int a = 6;
System.out.println(a);
}
void sampleMethod(int n){
System.out.println(n);
System.out.println(y);
}
}
Ans. (i) Method argument is n, and its value is 5. (ii) Class variable is x, and its value is 7.
(iii) Local variable is a, and its value is 6.
SECTION B
14. Define a class ElectricBill with the following specifications: [2017]
class : ElectricBill
Instance variables/data members
String n : to store the name of the customer.
int units : to store the number of units consumed.
double bill : to store the amount to be paid.
Methods
void accept() : to accept the name of the customer and the number of units consumed.
void calculate() : to calculate the bill as per the following tariff:
Number of units Rate per unit
First 100 units – Rs. 2.00
Next 200 units – Rs. 3.00
Above 300 units – Rs. 5.00
A surcharge of 2.5% is charged if the number of units consumed is above 300 units.
void print() : To print the details as follows:
Name of the customer: ________
Number of units consumed: ________
Bill amount: ________
Write a main() method to create an object of the class and call the above member functions.
Ans. import java.util.*;
291
Class as the Basis of all Computation 291

