Page 286 - CA_Blue( J )_Class10
P. 286
// Since, both the instance variables and the local variables are same, "this"
//keyword is used to separate both the variables.
void display(){
s=n1+n2;
System.out.println("Sum : "+s);
d=n1-n2;
System.out.println("Difference: "+d);
}
public static void main()
{ sum ob = new sum();
ob.assign(20, 10);
//The assign() method has 2 parameters, so two values should be given at the
//time of calling the method.
ob.display();
//from static method non-static method cannot be called. So, an object "ob" is
//called.
}
}
9. Name the Java keyword that:
(i) indicates that only one instance of a variable is created for any number of objects of the class.
(ii) stores the address of the currently calling object.
Ans. (i) static (ii) this
10. Write a Java statement to create an object named computer of the class subject.
Ans. subject computer = new subject();
11. Write an example that is creating an object of an inbuilt class.
Ans. Scanner sc= new Scanner();
12. What is a local variable?
Ans. A local variable has a very limited scope as it can be accessed within the method in which it is declared. Outside the curly brackets
of the method, it has no existence.
D. Assertion and Reasoning based questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true, and R is the correct explanation of A.
b. Both A and R are true, but R is not the correct explanation of A.
c. A is true, but R is false.
d. A is false, but R is true.
1. Assertion (A): A class in object oriented programming serves as a blueprint for creating objects.
Reason (R): Objects and class are same.
2. Assertion (A): Inheritance allows a class to use methods and properties of another class.
Reason (R): Inheritance helps to achieve polymorphism in object oriented programming.
3. Assertion (A): Encapsulation is a method that allows one class to inherit the properties of another class.
Reason (R): Encapsulation restricts direct access to some of the object's components, which can prevent the accidental
modification of data.
4. Assertion (A): Polymorphism allows objects to be treated as instances of their parent class.
Reason (R): Polymorphism in object-oriented programming is achieved by method overriding and method overloading.
Ans. 1. c 2. b 3. d 4. b
284284 Touchpad Computer Applications-X

