Class X
(Time: Two Hours) SECTION A (40 Marks)
Answer all questions from this Section
Question 1.
(a)Give one example of a primitive data type and composite data type. [2]
Ans. Primitive type: byte/short/int/long/float/double/char/boolean
Composite type: classes/interface/arrays
(b) Give one point of difference between unary and binary operators. [2]
Ans. Unary operators work on a single operand eg. ++a while binary operators work on two operands eg. a+b
© Differentiate between call by value or pass by value and call by reference or pass by reference [2]
Ans. Call by value method creates a new copy of formal parameters and the changes made to them in the called function are not reflected on the actual arguments in the calling function. They work for primitive data types while call by reference method does not create a new copy rather works on the reference of actual arguments and changes made to them in the called function are reflected in the calling function. They work for reference data types.
(d) Write java expression for √2as+u2 [2]
Ans. double d= Math.sqrt((2*a*s + u*u));
(e) Name the type of error (syntax, runtime or logical error) in each case given below: [2]
Ans. (i) Division by a variable that contains a value of zero : Runtime error
(ii) Multiplication operator used when the operation should be division : Logical error
(iii) Missing semicolon: Syntax error
Question 2.
(a) Create a class with one integer instance variable. Initialize the variable using :
(i) Default constructor
(ii) parameterized constructor
Ans.
class Initialize
{
int x; //instance variable
Initialize() //default constructor
{
x=0;
}
Initialize(int a) //parameterized constructor
{
x=a;
}
}
(b) Complete the code given below to create an object of Scanner class: [2]
Ans. Scanner sc=new Scanner (System.in); © What is an array? Write a statement to declare an integer array of 10