LIWA

Class as the Basis of All Computation

ICSE Class 10 · Computer Applications · Chapter 2

What this chapter covers

Key points

Questions answered

Define an object in Java terms.
An object is an identifiable entity that has characteristics describing its state and actions describing its behaviour; in Java it is an instance of a class, created with `new`.
What is meant by the state of an object? Give an example.
The state is the set of values held by the object's member variables at a given moment. For a bank account with balance ₹3000 and account number 1021, those two values form its state.
Why is a class called an object factory?
Because it is the template from which any number of objects of the same kind can be produced, each with its own copy of the member variables.
Why is a class called an abstraction for a set of objects?
Because it records only the essential characteristics and behaviour shared by all objects of that kind and leaves out the particular values of each one.
Distinguish between a class and an object (two points).
A class is a blueprint, while an object is an actual instance made from it. A class is declared once with the keyword `class`, while many objects can be created from it with the operator `new`, each getting its own memory for member variables.
Name the member variables and member methods suitable for a class `MobilePhone`.
Member variables: `brand`, `batteryLevel`, `volume`. Member methods: `makeCall()`, `charge()`, `increaseVolume()`. (Other sensible choices are also correct.)
Why is calling a method described as sending a message to an object?
Because the statement asks a particular object to perform one of its actions; the object responds by running its own method, which usually reads or changes its own state.
Why is a class called a user-defined data type?
Because once the programmer writes the class, its name can be used to declare variables just like `int`, and the type has its own data and its own methods.

Past board exam questions

ICSE 2026 board paper · 15 marks

Define a class named StepTracker with the following specifications: Member Variables: String name — stores the user's name. int sw — stores the total number of steps walked by the user. double cb — stores the estimated calories burned by the user. double km — stores the estimated distance walked in kilometers. Member Methods: void accept() — to input the name and the steps walked using Scanner class methods only. void calculate() — calculates calories burned and distance in km based on steps walked using the following estimation table: | Metric | Calculation Formula | |---|---| | Calories Burned | steps walked × 0.04 (e.g., 1 step burns 0.04 calories) | | Distance (Km) | steps walked / 1300 (e.g., 1300 steps is approx. 1 km) | void display() — Display the calories burned, distance in km and the user's name. Write a main method to create an object of the class and invoke the methods.

Show answer
``` import java.util.Scanner; class StepTracker { String name; int sw; double cb; double km; void accept() { Scanner sc = new Scanner(System.in); System.out.print("Enter name: "); name = sc.nextLine(); System.out.print("Enter steps walked: "); sw = sc.nextInt(); } void calculate() { cb = sw * 0.04; km = sw / 1300.0; } void display() { System.out.println("Calories burned: " + cb); System.out.println("Distance in km: " + km); System.out.println("Name: " + name); } public static void main(String args[]) { StepTracker obj = new StepTracker(); …

ICSE 2026 board paper · 1 mark

Consider the following statements: ``` Computer desktop = new Computer( ); Computer Mainframe = new Computer( ); ``` Name the objects of the class given above:

  1. Desktop, Mainframe
  2. desktop, Mainframe
  3. Computer, Mainframe
  4. Computer, desktop
Show answer
desktop, Mainframe

ICSE 2025 board paper · 15 marks

Define a class named CloudStorage with the following specifications: • Member Variables: - int acno - stores the user's account number. - int space - stores the amount of storage space in GB purchased by the user. - double bill - stores the total price to be paid by the user. • Member Methods: - void accept() - prompts the user to input their account number and storage space using Scanner class methods only. - void calculate() - calculates the bill total price based on the storage space purchased using the pricing table provided: | Storage range | Price per GB (Rs) | |---|---| | First 15 GB | 15 | | Next 15 GB | 13 | | Above 30 GB | 11 | - void display() - displays the account number, storage space and bill to be paid. Write a main method to create an object of the class and invoke the methods of the class with respect to the object.

Show answer
import java.util.Scanner; class CloudStorage { int acno; // account number int space; // storage space purchased in GB double bill; // total price to be paid void accept() { Scanner sc = new Scanner(System.in); System.out.print("Enter account number: "); acno = sc.nextInt(); System.out.print("Enter storage space (GB): "); space = sc.nextInt(); } void calculate() { if (space <= 15) bill = space * 15; else if (space <= 30) bill = 15 * 15 + (space - 15) * 13; else bill = 15 * 15 + 15 * 13 + (space - 30) * 11; } void display() { …

ICSE 2025 sample paper · 15 marks

Define a class with the following specifications: Class name: Bank Member variables: double p – stores the principal amount double n – stores the time period in years double r – stores the rate of interest double a – stores the amount member methods: void accept () – input values for p and n using Scanner class methods only. void calculate () – calculate the amount based on the following conditions: | Time in (Years) | Rate % | |---|---| | Upto ½ | 9 | | > ½ to 1 year | 10 | | > 1 to 3 years | 11 | | > 3 years | 12 | a = p(1 + (r)/(100))n void display () – display the details in the given format. ``` Principal Time Rate Amount xxx xxx xxx xxx ``` Write the main method to create an object and call the above methods.

Show answer
```java import java.util.Scanner; class Bank { double p, n, r, a; // principal, time in years, rate, amount void accept() { Scanner sc = new Scanner(System.in); System.out.print("Enter the principal amount: "); p = sc.nextDouble(); System.out.print("Enter the time period in years: "); n = sc.nextDouble(); } void calculate() { if (n <= 0.5) r = 9; else if (n <= 1) r = 10; else if (n <= 3) r = 11; else r = 12; a = p * Math.pow(1 + r / 100, n); } void display() { System.out.println("Principal\tTime\tRate\tAmount"); …

ICSE 2025 board paper · 1 mark

Which of the following is true for the given object creation statement? Game cricket = new Game( );

  1. Game is an object of cricket class
  2. New keyword creates object Game
  3. Game is a class and cricket is an object
  4. Game and cricket are objects
Show answer
Game is a class and cricket is an object

ICSE 2025 board paper · 1 mark

Which of the following is user defined data type? | 1. array | 3. class | |---|---| | 2. double | 4. boolean |

  1. only 1
  2. 1 and 3
  3. only 2
  4. only 4
Show answer
1 and 3

ICSE 2025 compartment paper · 2 marks

In the example given below of class Cat, identify the variable and the methods: | Cat | |---| | Name | | meow() eat() play() |

Show answer
Variable (data member): Name Methods (member methods): meow(), eat(), play()

ICSE 2024 sample paper · 15 marks

Define a class called with the following specifications: Class name: Eshop Member variables: String name: name of the item purchased double price: Price of the item purchased Member methods: void accept(): Accept the name and the price of the item using the methods of Scanner class. void calculate(): To calculate the net amount to be paid by a customer, based on the following criteria: | Price | Discount | |---|---| | 1000 – 25000 | 5.0% | | 25001 – 57000 | 7.5 % | | 57001 – 100000 | 10.0% | | More than 100000 | 15.0 % | void display(): To display the name of the item and the net amount to be paid. Write the main method to create an object and call the above methods.

Show answer
import java.util.Scanner; class Eshop { String name; // name of the item purchased double price; // price of the item purchased double net; // net amount to be paid void accept() { Scanner sc = new Scanner(System.in); System.out.print("Enter name of the item: "); name = sc.nextLine(); System.out.print("Enter price of the item: "); price = sc.nextDouble(); } void calculate() { double rate; // discount percentage if (price >= 1000 && price <= 25000) rate = 5.0; else if (price > 25000 && price <= 57000) rate = 7.5; else if …