Sunday 24 January 2016

Solved Theory Questions of ICSE Board Exam Part-3

(a) Define the term Byte Code. [2]
Ans. The Java compiler compiles the source programs into an intermediate code called the Java Byte Code which is interpreted by the Java Virtual Machine (JVM)
(b) What do you understand by type conversion? [2]
Ans. Type conversion or casting is the conversion of the data type of a literal from one type to another. There are tow types of types of casting – implicit casting and explicit casting.
(c) Name two jump statements and their use. [2]
Ans. break and continue are the two jump statements in Java. break is used to force early termination of a loop. continue is used to move to the next iteration of the loop while skipping the remaining code in the current iteration.
(d) What is Exception ? Name two Exception Handling Blocks. [2]
Ans. An Exception is an error which occurs during the execution of a program. The exception handling blocks are try, catch and finally.
(e) Write two advantages of using functions in a program. [2]
Ans. i) Function make code reusable.
ii) Functions improve modularity and facilitate easy debugging.
Question 2.
(a) State the purpose and return data type of the following String functions: [2]
(i) indexOf ( )
(ii) compareTo ( )
Ans. i) indexOf() returns the index of the character or String passed as the parameter in the string on which is invoked.
Return type is int.
ii) compareTo() lexicographically compares the String passed as an argument to the String on which it is invoked.
Return type is int.
(b) What is the result stored in x, after evaluating the following expression [2]
1int x = 5;
2x = x++ * 2 3 * –x;
Ans. x = 5 * 2 + 3 * -6
x = 10 – 18
x = -8
(c) Differentiate between static and non-static data members. [2]
Ans. i) static variables belong to the class and all object share a single instance of the static variables. Non static varaiables belong to the objects. Each object has a copy of these members.
ii) static functions can access only static data members. Non static function can access both static and non static data members.
(d) Write the difference between length and length() functions. [2]
Ans. length is a property of an array which gives the size of the array. length() is a function of the String class which returns the size of the String.
(e) Differentiate between private and protected visibility modifiers. [2]
Ans. private members are accessible only in the class in which they have been defined. protected members are accessible in the class in which they have been defined as well in the sub classes of that class.
Question 3
(a) What do you understand by data abstraction? Explain with an example.[2]
Ans. Abstraction refers to representing the essential features of a system without considering all the details. Example: When we drive a car, we concentrate on how to drive it without bothering ourselves on how the engine works and other things.
(b) What will be the output of the following code?
(i) [2]
1int m=2;
2int n=15;
3for(int i = 1; i<5; i++);
4m++; –-n;
5System.out.println("m=" +m);
6System.out.println("n="+n);
Ans.
1m=3
2n=14
Note that there is a semicolon at the end of the loop. So, it is an empty loop and does’t affect the values of m and n.
(ii) [2]
1char x = 'A' int m;
2m=(x=='a') ? 'A' : ‘a’;
3System.out.println("m="+m);
Ans.
1m=97
(c) Analyse the following program segment and determine how many times tne
loop will be executed and what will be the output of the program segment. [2]
1int k=1, i=2;
2while (++i<6)
3k*=i;
4System.out.println(k);
Ans. Following are the iterations of the loop
13 < 6 ---- k = 1 * 3 = 3
24 < 6 ---- k = 3 * 4 = 15
35 < 6 ---- k = 12 * 5 = 60
46 < 6 ---- false
The loop will run three times and output is 60
1
(d) Give the prototype of a function check which receives a character ch and an integer n and returns true or false. [2]
Ans.
1public boolean function(char ch, int n)
(e) State two features of a constructor. [2]
Ans. i) A constructor has the same name as that of a class.
ii) A constructor does not have any return type.
iii) A constructor is automatically called during object creation.
(f) Write a statement each to perform the following task on a string:
(i) Extract the second last character of a word stored in the variable wd. [2]
Ans.
1char ch = wd.charAt(wd.length()-2);
(ii) Check if the second character of a string str is in uppercase. [2]
Ans.
1boolean result = Character.isUpperCase(str.charAt(1));
(g) What will the following functions return when executed? [2]
(j) Math.max(-17, -19)
(ii) Math.ceil(7.8)
Ans. i) -17
ii) 8.0
(h) (i) Why is an object called an instance of a class?
(ii) What is the use of the keyword import? [2]
Ans. i) An object is called an instance of a class because the objects contains a copy of all the instance variables of the class.
ii) The import keyword is used to import classes from external packages.