(a) Create a class with one integer instance variable. Initialize the variable using:

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

21 Mark · 2012 · Section A · 2012 Paper

(a) Create a class with one integer instance variable. Initialize the variable using:

Show SolutionHide Solution↓
class Number {
    int a;

    public Number() {
        a = 0;
    }

    public Number(int x) {
        a = x;
    }
}

(b) Complete the code below to create an object of Scanner class:

    Scanner sc = ____ Scanner(__________);

Scanner sc = new Scanner(System.in);

(c) What is an array? Write a statement to declare an integer array of 10 elements.

An array is a structure to store a number of values of the same data type in contiguous memory locations. The following statement declares an integer array of 10 elements:

int arr[] = new int[10];

(d) Name the search or sort algorithm that:

  1. 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.
  2. At each stage, compares the sought key value with the key value of the middle element of the array.
  1. Selection Sort
  2. Binary Search

(e) Differentiate between public and private modifiers for members of a class.

public modifier makes the class members accessible both within and outside their class whereas private modifier makes the class members accessible only within the class in which they are declared.

← Previous questionNext question →

Browse the free Computer Applications sample bank