Computer Application Paper Solved 2012

Only available on StudyMode
  • Topic: Java, Data type, Primitive data type
  • Pages : 11 (1978 words )
  • Download(s) : 125
  • Published : December 4, 2012
Open Document
Text Preview
Computer Applications
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 elements[2] Ans.   An array is a structure created in memory to store multiple similar type of data under a single subscripted variable name. int a[]=new int[10];

(d) Name the search or sort algorithm that :       [2] (i) Makes several passes through the array, selecting the next smallest item in the array each time and placing it where it belongs in the array :  Selection sort (ii) At each stage, compares the sought key value with the key value of the middle element of the array: Binary search  

(e) Differentiate between public and private modifiers for members of a class [2] Ans. The scope of private members of a class is within the class itself whereas the the scope of the public members of a class is outside the class also ( outside the package also). Question 3.

(a) What are the values of x and y when the following statements are executed?[2] int a=63, b=36;
boolean x = (a>b) ? true :  false ;
int y=(a<b) ? a : b;
Ans.
x=true
y=36
(b)  State the values of n and ch.      [2]
char c=’A’;
int n=c+1;
char ch=(char)n;
Ans.    n=66        ,      ch=B
 
© What will be the result stored in x after evaluating the following expression?[2] int x = 4;
x+= (x++)+(++x)+x;
Ans. 
x=4+4+6+6
=20
(d) Give output of the following program segment:     [2] double  x= 2.9 ,  y=2.5;
System.out.println(Math.min(Math.floor(x),y));
System.out.println(Math.max(Math.ceil(x),y));
Ans.
2.0
3.0
(e)  State the output of the following program segment:   [2] String s=”Examination”;
int n=s.length();
System.out.println(s.startsWith(s.substring(5,n)));
System.out.println(s.charAt(2) == s.charAt(6));
Ans.
false
true
(f) State the method that:      [2]
(i)  Converts a string to a primitive float data type   :  parseFloat() (ii) Determines if the specified character is an upper case character: isUpperCase()  
(g)  State the data type and values of a and b after the following segment is executed:     [2] String  s1= “Computer”,  s2=“Applications”;
a = (s1.compareTo(s2));
b =...
tracking img