You are on page 1of 77

SELF ASSESSMENT TEST

COMPUTER APPLICATIONS
ANSWERS
UNIT-1
Maximum Marks : 30  Timing : 1 Hour

STAND ALONE MCQs


1. Option (A) is correct. 3. Option (D) is correct.
Explanation: The classes are grouped together Explanation: All the methods such as min(),
into related sets that are called packages, and abs() and ceil() are the methods of Math class
each package is stored in a separate directory. while parseInt() is a method of Integer class.
A class in a package can access any of the other
4. Option (A) is correct.
classes in the package.
2. Option (A) is correct. Explanation: The max() method returns the
highest value given as argument. Thus, -17 is
Explanation: All the variables and methods greater than -19 and so it is the correct answer.
in Math class are static, and itself it is final
in nature. This means the user can’t derive
new classes from Math. The Math class
can’t be instantiated. The Math class is a
conglomeration of methods and constants for
performing mathematical computations.

ASSERTION AND REASON MCQs


5. Option (C) is correct. 6. Option (C) is correct.
Explanation: The Object class is the superclass Explanation: Method is a function which needs
for all classes in Java. Because all classes are to be called by the objects of a class. A method
derived from Object, the methods defined in contains number of valid Java statements.
Object are shared by all classes. This results Name of the method is different from that of a
in a core set of methods that all Java classes class. Method can be static.
are guaranteed to support. Object includes
methods for making copies of an object, testing
objects for equality, and converting the value
of an object to a string.

CASE-BASED MCQs
7. Option (A) is correct. 8. Option (C) is correct.
Explanation: Primitive data type are those data Explanation: Primitive data types are the eight
types whose meaning are already defined in primitives defined in Java are int, byte, short,
Java. There are eight primitive data types. long, float, double, boolean, and char – those
aren’t considered objects and represent raw
values.
2 ] Oswaal ICSE Chapterwise & Topicwise Question Bank For Semester-2 COMPUTER APPLICATIONS, Class – X

9. Option (C) is correct. 10. Option (A) is correct.


Explanation: Arrays are used to hold many Explanation: Data type boolean can only have
values of same type in it. Classes define the a value of true or false. Internal to Java, a
structure of the Java program. An interface in boolean value is a 1-bit logical quantity.
the Java programming language is an abstract
type that is used to specify a behavior that
classes must implement. They are similar to
protocols. Interfaces are declared using the
interface keyword, and may only contain
method signature and constant declarations.

1 Mark Questions
11. For r1: 12. The data type of res is boolean and value of res after
Math.min(- 2.83, -5.83)=-5.83 executing the code will be true.
13. Primitive Data Types – byte, short, int, long, float,
Math.abs(-5.83)= 5.83
double, char, boolean
Thus, r1= 5.83
Composite Data Type – Class and Array
Thus, the value of the variable r1 is 5.83.

2 Marks Questions
14. A class is composed of instance variables which are programs, from compilers to text-based adventure
of different data types. Hence, a class can be viewed games.
as a composite data type which is composed of 16. The floor() returns the largest (closest to positive
primitive and other composite data types. infinity) double value that is less than or equal to the
15. The StringTokenizer class provides a means of argument and is equal to a mathematical integer. Its
converting text strings into individual tokens. By syntax is: floor(double a)
specifying a set of delimiters, you can parse text The pow() returns the value of the first argument
strings into tokens using the StringTokenizer class. raised to the power of the second argument. Its
String tokenization is useful in a wide variety of syntax is : pow(double a, double b)

3 Marks Questions
17. import java.io.*; logarithm of number is” + Math.log(n));
import java.lang.*; System.out.println(“The Absolute value
import java.math.*; of number is” + Math.abs(n));
public class Number System.out.println(“The Square root of
number is” + Math.sqrt(n));
{
}
static double logarithm, absolute, sq_
root; }
public static void main(String main[]) }
throws IOException 18. import java.io.*;
{ import java.lang.*;
double n; import java.math.*;
BufferedReader br= public class Sq_Root
{
new BufferedReader(new
InputStreamReader(System.in)); static double sq_root;
public static void main(String q[])
{
throws IOException
System.out.println(“Enter no”);
{
n=new Double(br.readLine()). double n;
doubleValue();
BufferedReader br =
System.out.println(“The Natural new BufferedReader(new
SOLUTIONS [ 3
InputStreamReader(System.in)); number is”
{ + Math.sqrt(n));
System.out.println(“Enter no”); }
n = new Double(br.readLine()). }
doubleValue(); }
System.out.println(“The Square root of

5 Marks Questions
java.net – Classes for networking support, including
19. The different class packages in Java are as follows: Socket and URL (a class to represent references to
java.lang – Classes that apply to the language itself, documents on the World Wide Web).
including the Object class, the String class, and the java.awt – This is the Abstract Windowing Toolkit.
System class. It also contains the special classes for It contains classes to implement graphical user
the primitive types (Integer, Character, Float, and interface features, including classes for Window,
so on). Menu, Button, Font, CheckBox, and so on. It also
java.util – Utility classes, such as Date, as well includes mechanisms for managing system events
as simple collection classes, such as Vector and and for processing images (in the java.awt.Image
Hashtable. package).
java.io – Input and output classes for writing to and java.applet – Classes to implement Java applets.
reading from streams (such as standard input and
output) and for handling files.
SOLUTIONS [ 1

SELF ASSESSMENT TEST


COMPUTER APPLICATIONS
UNIT-2
Maximum Marks : 30  Timing : 1 Hour

STAND ALONE MCQs


1. Option (B) is correct. Explanation: Option (A), (B) and (C) are the
Explanation: The void return type shows that a three types of error that exist in Java. Option
method does not return any value. (D) is not a type of error at all.

2. Option (A) is correct. 4. Option (A) is correct.

Explanation: The new keyword is used to Explanation: As given in the question, float is
create a new package and object. the return type, sum is the name of the method
which takes integer argument. All these points
3. Option (D) is correct. are available in the Option (A).

ASSERTION AND REASON MCQs


5. Option (D) is correct. Explanation: The curly braces determines the
Explanation: Public data modifiers can be scope of the variable. The reference s vanishes
accessed from outside the class but private data at the end of the scope. However, the String
modifiers cannot be accessed from outside the object that was pointing to is still occupying
class. These can be used within the class. memory. In this bit of code, there is no way to
access the object because the only reference to
6. Option (C) is correct. it is out of scope.

CASE-BASED MCQs
7. Option (A) is correct. Explanation: When you extend an existing
Explanation: Inheritance is one of the property class, the new class has all the properties and
of object-oriented programming framework methods of the class that you extend. You
where one class can be extended and its supply new methods and data fields that
variables and methods can be used by the apply to your new class only. The concept of
other class which extended it. The class whose extending a class to obtain another class is
variables and methods are to be reused is called called inheritance.
base class. The other class using the variables 10. Option (C) is correct.
and methods of its base class is called derived
class. Explanation: The extends keyword is used to
extend the parent class. The derived class can
8. Option (C) is correct. be able to reuse the behaviours and attributes
Explanation: The parent which is being of the base class.
extended so that other classes can use its
variables and methods is called base class or
super class.
9. Option (C) is correct.
2 ] Oswaal ICSE Chapterwise & Topicwise Question Bank For Semester-2 COMPUTER APPLICATIONS, Class – X

1 Mark Questions
11. Here, x = 2 =8
y=3 The expression x*(++y)%z evaluated to 8 when
z=9 the variables are a = 2, b = 3 and c = 9.
Thus, 12. The data in an object are called its instance field.
x*(++y)%z 13. There are four types of access specifiers:
= 2*(++3)%9 (i) default (ii) private
(iii) protected (iv) public

2 Marks Questions
14. (i) public members can be accessed from any other are accessible in the class in which they have been
class or package. defined as well in the sub classes of that class.
(ii) private members can only be accessed within the 16. Abstraction refers to represent the essential features
declared class. of a system without considering all the details.
15. Private members are accessible only in the class in Example: When we drive a car, we concentrate on
which they have been defined. Protected members how to drive it without bothering ourselves on how
the engine works and other things.

3 Marks Questions
17. import java.io.*; public static void main(String args[])
public class overload throws IOException
{ {
void volumes (double s) overlaodvl = new overlaod();
{ vl.volumes(9.0);
System.out.println( “ Volume of a vl.volumes(3.14,6.0);
cube:” + (s*s*s)); vl.volumes(4.0,5.0,6.0);
} }
void volumes (double pi, double r) }
{ 18. A class encapsulates the data (instance variables)
System.out.println(“ Volume of a and methods.
sphere:” + (1.33*pi*r*r*r)); (i) Public specifier: When a member of a class is
} modified by the public specifier, then that member
can be accessed by any other code i.e., it is directly
void volumes (double l, double b,
accessible from all other classes.
double h)
(ii) Private specifier: When a member of a class is
{
specified as private, then that member can only
System.out.println(“ Volume of a be accessed by other members of its class i.e., it is
cuboid:” + (l*b*h)); private to its class.
}

5 Marks Questions
19. import java. io.*; {
import static java.lang.Boolean.*; n = 0;
public class Special }
{ void read()
int n: {
Special() BufferedReader br = new BufferedReader
SOLUTIONS [ 3
(new InputStreamReader(System.in)); return True;
System.out.println(“Enter any else
number”); return False;
n = Integer.parseInt(br.readLine()); }
int factorial (int x) void display ()
} {
if (x == 0) Boolean res = isspecial();
return ^; if (res = = Ture)
else System.out.println(“Enterend no is a
return x* factorial (x - ^); special number”);
} else
Boolean inspecial() System.out.println(“Not a special
{ no”);
int num= n, sum = 0; }
while (num > 0) public static void main(String args[])
{ {
int t = num%10; Special sp = new Special ();
int t = factorial (t); sp read ();
num = sum + t; sp display();
num = num/^0; }
}
if(n = = run)
SOLUTIONS [ 1

SELF ASSESSMENT TEST


COMPUTER APPLICATIONS
UNIT-3
Maximum Marks : 30  Timing : 1 Hour

STAND ALONE MCQs


1. Option (A) is correct. 3. Option (A) is correct.
Explanation: Bubble sort is the most widely Explanation: Since, the array index starts from
used but least efficient technique for sorting 0. Thus, the array index of the array a[10] is
one dimensional array. Its algorithm is simple from 0 to 9.
and programming is easy. The technique is
named so as each element of the array bubbles 4. Option (B) is correct.
up to its position, as the process is continued. Explanation: Items of an array can be accessed
2. Option (C) is correct. using random access. That is, every element
of the array is equally accessible at any given
Explanation: Array variables indicate the type time.
of object the array will hold (just as they do
for any variable) and the name of the array,
followed by empty brackets ([]).An alternate
method of defining an array variable is to put
the brackets after the type instead of after the
variable.

ASSERTION AND REASON MCQs


5. Option (D) is correct. Explanation: The length of a character array is
Explanation: Binary search works only on found by accessing the length attribute of the
sorted data while linear search works both on array as shown below:
sorted or unsorted data.Binary search is better char[] array = new char[7];
and faster than linear search.Linear search uses intlength of Char Array = array. length;
sequential approach while binary search uses The length of a String object is found by
divide and conquer approach. invoking the length() method which returns
6. Option (D) is correct. the length as an int.
String str = “java”;
int lengthOfString = str.length();

CASE-BASED MCQs
7. Option (C) is correct. Explanation: The opening curly braces({)
Explanation: The ++ is an increment operator signifies the start of the scope of the instance or
and it is a unary operator, as it takes one class variables and the closing curly braces(})
argument. denotes the end of the scope.

8. Option (C) is correct. 9. Option (D) is correct.


Explanation: An arithmetic expression can
contain a mixture of literals which can be
operators, variables and subscripted variables.
2 ] Oswaal ICSE Chapterwise & Topicwise Question Bank For Semester-2 COMPUTER APPLICATIONS, Class – X

10. Option (B) is correct. Explanation: The array data[ ] contains four
items of type int.

1 Mark Questions
11. Searching is the process to determine whether the data of the same data type. The following statement
given element is present in the array or not. While, declares an integer array of 10 elements -
Sorting is the process of arranging data in ascending int arr[] = new int[10];
or descending order.
13. char is two bytes. So a[4] will be 2*4=8 bytes.
12. An array is a reference data used to hold a set of
float is 4 bytes. So p[4] will be 4*4=16 bytes

2 Marks Questions
14. (i) Linear search scans one item at a time, without an index to the array and in the given program
jumping to any item whereas binary search cuts segment,it takes values from 0 to 5. a[5] would
down the search and find the middle of a sorted list. result in an ArrayIndexOutofBounds Exception.
(ii) Linear search works for both sorted and unsorted Therefore, the loop condition should be changed to
data whereas binary search only works for sorted i<=4. The given program segment creates an array
data. of size 5 and stores numbers from 0 to 4 in the array.
15. Error 1 : The size of an array is specified using 16. Whenever a program attempts to index an array
square brackets [] and not parentheses (). with an index that is a negative number, Java will
issue an ArrayIndexOutOfBoundsException and
Error 2 : Since the array is of length 5, the indices
terminate the program.
range from 0 to 4. The loop variable i is used as

3 Marks Questions
17. import java.io.*; System.out.println(“Maximum Value=
class Q6_2007 “+max_val);
{ System.out.println(“Minimum Value=
“+min_val);
public static void main(String args[])
throws IOException System.out.println(“Sum Of The
Element= “+sum_element);
{
}
int number[ ]={2,5,4,1,3};
}
int min_val, max_val, sum_element=0,
i; 18.
int n=number.length; Linear Search Binary Search
max_val=number[0]; (i) In linear search, the In binary search, the
min_val=number[0]; element to be searched element to be searched
for(i=0;i<n;++i) is compared with every is compared every time
element of the array. with middle element of
{
the divided array.
if(max_val<number[i])
{ (ii) Linear search takes Binary search takes
longer time than binary lesser time than linear
max_val=number[i];
search. search.
}
(iii) The array need not be The array needs to
if(min_val>number[i]) sorted. sorted.
{
min_val=number[i];
}
sum_element=sum_element+number[i];
}
SOLUTIONS [ 3

5 Marks Questions
19. import java.io.*; name[j])>0)
class sort_city { // if city name at ‘i’ is greater
{ than city name at ‘j’
public static void main(String args[]) // then interchanging the names at ‘i’
throws IOException and ‘j’
{ temp=city_name[i]; //storing name in a
variable ‘temp’
String city_name[ ]= {“Delhi”,”Bangalo
re”,”Agra”,”Mumbai”,”Calcutta”}; city_name[i]=city_name[j];
String temp; city_name[j]=temp;
int i, j; }
System.out.println(“Original Array”); }
for(i=0;i<5;++i) }
{ System.out.println(“Sorted Array:”);
System.out.println(city_name[i]); for(i=0;i<5;++i)
} {
for(i=0;i<4;++i) System.out.println(city_name[i]);
{ }
for(j=i+1;j<5;++j) }
{ //comparing city name at ‘i’ with }
city name at ‘j’ //
if(city_name[i].compareTo(city_
SOLUTIONS [ 1

SELF ASSESSMENT TEST


COMPUTER APPLICATIONS
UNIT-4
Maximum Marks : 30  Timing : 1 Hour

STAND ALONE MCQs


1. Option (A) is correct. 3. Option (C) is correct.
Explanation: Binary search, also known as Explanation: The statement”ACHIEVEMENT”.
half-interval search, logarithmic search, or replace(‘E’, ‘A’); replaces all the occurrences of
binary chop, is a search algorithm that finds ‘E’ with ‘A’.
the position of a target value within a sorted Thus, the output is ACHIAVAMANT.
array. Binary search compares the target value
4. Option (C) is correct.
to the middle element of the array.
2. Option (A) is correct. Explanation: The trim( )method returns a copy
of the invoking string from which any leading
Explanation: The endsWith() method checks and trailing whitespace has been removed. It
whether the string ends with the specified has this general form:
suffix. It returns Boolean value as True or False. String trim( )

ASSERTION AND REASON MCQs


5. Option (B) is correct. 6. Option (C) is correct.
Explanation: In Java, strings are represented by Explanation: The String class provides an
one of two classes: opportunity to create a null string by declaring
•String. Best used for string constants--that is, as public String().
for strings that are not going to change after
they’re created.
•StringBuffer. Used for strings those require a
lot of manipulation.
Thus, a string cannot be accessed directly. An
object of the classes String or StringBuffer is to
be created in order to access a string.

CASE-BASED MCQs
7. Option (A) is correct. Explanation: The toUpperCase() method is
Explanation: As given in the question, the class used to convert the string into uppercase.
name is WordsInSentence. As given in the question, the string had to
converted into uppercase, thus the method
8. Option (A) is correct. toUppercase() is used.
Explanation: The new keyword is used to 10. Option (D) is correct.
create an instance of the class.
Explanation: To check whether the string starts
9. Option (C) is correct. with the letter ‘A’, the method startsWith is
used.
2 ] Oswaal ICSE Chapterwise & Topicwise Question Bank For Semester-2 COMPUTER APPLICATIONS, Class – X

1 Mark Questions
11. This is so because Java uses the concept of string (ii) 5
literal. This means that if one reference variable 13. false
changes the value of an object, it will be affected to
JAI
all the reference variables.
12. (i) USA

2 Marks Questions
14. The toLowercase() converts all of the characters characters with empty String.
in the String to lower case using the rules of the 16. There are two ways to check equivalence of two
default locale. Strings in Java. These are:
The tocharArray() converts this string x to a new • using ‘==’ operator – This checks for value of
character array. String as well as reference
15. We can use replaceAll method to replace all the • using equals( ) method – This is more preferably
occurrences of a String with another String. It used in programming.
accepts String as argument, so Character class is
used to create String and use it to replace all the

3 Marks Questions
17. public class JoinStrings { public void main(String a)
public static void main(String[] {
args) { System.out.println(“You have entered
String firstString = “Many “; the string = “ + a);
String secondString = “hands “; int x = a.length( );
String thirdString = “make light a=” “+a;
work”; for(int y = 0; y < x; y++)
String myString; // Variable to {
store results
char b = a.charAt(y);
// Join three strings and
if(b == ‘ ‘)
store the result
System.out. print(Character.
myString = firstString +
toUpperCase(a.charAt(y + 1)) + “.”);
secondString + thirdString;
}
System.out.println(myString);
}
}
}
}
18. class ShortForm
{

5 Marks Questions
19. import java.io.*; char c, chr;
class low_up int i, l;
{ InputStreamReader reader = new
public static void main(String args[]) InputStreamReader(System.in);
throws IOException BufferedReader inp= new
{ BufferedReader(reader);
String s; System.out.println(“Enter Any Word:”);
String wrd; wrd=inp.readLine();
SOLUTIONS [ 3
System.out.println(“ Original Word : || c==’u’)
“+wrd); {
//if(wrd.isUpperCase(wrd)) // //int x=c+1; //
wrd= wrd.toLowerCase(); chr = (char)(c+1);
System.out.println(“The word in Lower System.out.print(chr);
Case: “+wrd);
}
l = wrd.length();
else
System.out.println(“The Require Word
{
:”);
System.out.print (c);
for(i=0;i<l;++i)
}
{
}
c = wrd.charAt(i);
}
if(c==’a’ || c==’e’ || c==’i’|| c==’o’
}



You might also like