(a) What do you understand by the term data abstraction? Explain with an example.

ICSE Class 10 Computer Applications PYQ · 2010 Paper · Section A

31 Mark · 2010 · Section A · 2010 Paper

(a) What do you understand by the term data abstraction? Explain with an example.

Show SolutionHide Solution↓

Data Abstraction refers to the act of representing essential features without including the background details or explanations. A Switchboard is an example of Data Abstraction. It hides all the details of the circuitry and current flow and provides a very simple way to switch ON or OFF electrical appliances.

(b)(i) What will be the output of the following code?

int m = 2;
int n = 15;
for(int i = 1; i < 5; i++);
m++;
--n;
System.out.println("m = " + m);
System.out.println("n = " + n);
m=6
n=14

As there are no curly braces after the for loop so only the statement m++; is inside the loop. Loop executes 4 times so m becomes 6. The next statement --n; is outside the loop so it is executed only once and n becomes 14.

(b)(ii) What will be the output of the following code?

char x = 'A';
int m;
m = (x == 'a')? 'A' : 'a';
System.out.println("m = " + m);
m = 97

The condition x == 'a' is false as X has the value of 'A'. So, the ternary operator returns 'a' that is assigned to m. But m is an int variable not a char variable. So, through implicit conversion Java converts 'a' to its numeric ASCII value 97 and that gets assigned to m.

(c) Analyze the following program segment and determine how many times the loop will be executed and what will be the output of the program segment.

int k = 1, i = 2;
while(++i < 6)
    k *= i;
System.out.println(k);
60

This table shows the change in values of i and k as while loop iterates:

ikRemarks
21Initial values
331st Iteration
4122nd Iteration
5603rd Iteration
660Once i becomes 6, condition is false and loop stops iterating.

Notice that System.out.println(k); is not inside while loop. As there are no curly braces so only the statement k *= i; is inside the loop. The statement System.out.println(k); is outside the while loop, it is executed once and prints value of k which is 60 to the console.

(d) Give the prototype of a function check which receives a character ch and an integer n and returns true or false.

boolean check(char ch, int n)

(e) State two features of a constructor.

  1. A constructor has the same name as that of the class.
  2. A constructor has no return type, not even void.

(f) Write a statement each to perform the following task on a string:

  1. Extract the second-last character of a word stored in the variable wd.
  2. Check if the second character of a string str is in uppercase.
  1. char ch = wd.charAt(wd.length() - 2);
  2. boolean res = Character.isUpperCase(str.charAt(1));

(g) What will the following function return when executed?

  1. Math.max(-17, -19)
  2. Math.ceil(7.8)
  1. -17
  2. 8.0

(h)(i) Why is an object called an instance of a class?

A class can create objects of itself with different characteristics and common behaviour. So, we can say that an Object represents a specific state of the class. For these reasons, an Object is called an Instance of a Class.

(h)(ii) What is the use of the keyword import?

import keyword is used to import built-in and user-defined packages into our Java program.

← Previous questionNext question →

Share on WhatsApp

Browse the free Computer Applications sample bank