Class as the Basis of All Computation
ICSE Class 10 · Computer Applications · Chapter 2
What this chapter covers
- Why Java is built around classes
- Objects encapsulate state and behaviour
- Member variables: attributes define state
- Member methods: operations define behaviour
- Class as an abstraction for a set of objects
- Class as an object factory
- Objects as instances of a class
- Real-life examples of class and object
- Primitive data types
- Composite data types
- Difference between primitive and composite data types
Key points
- In Java every variable and every method lives inside a class, so the class is the basis of all computation.
- An object has state (the values of its characteristics) and behaviour (the actions it can perform); it encapsulates both in one unit.
- Member variables, also called attributes, fields or instance variables, store the state of an object.
- Member methods, also called operations, define the behaviour of an object; calling one is called sending a message.
- A class is an abstraction for a set of objects: it keeps the shared characteristics and behaviour and leaves out the particular values.
- A class is an object factory: the operator `new` creates any number of objects from it, each with its own copy of the member variables.
- An object is an instance of a class; creating it is called instantiation.
- Java has eight primitive data types, built in, of fixed size, holding values directly.
- Composite data types such as classes, arrays and `String` combine other types, have no fixed size, and their variables hold references.
- A class is a user-defined data type: its name declares variables just as `int` does.
- Copying a primitive variable copies the value; copying a reference variable makes both names point to the same object.
Questions answered
Define an object in Java terms.
What is meant by the state of an object? Give an example.
Why is a class called an object factory?
Why is a class called an abstraction for a set of objects?
Distinguish between a class and an object (two points).
Name the member variables and member methods suitable for a class `MobilePhone`.
Why is calling a method described as sending a message to an object?
Why is a class called a user-defined data type?
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
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:
- Desktop, Mainframe
- desktop, Mainframe
- Computer, Mainframe
- Computer, desktop
Show answer
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
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
ICSE 2025 board paper · 1 mark
Which of the following is true for the given object creation statement? Game cricket = new Game( );
- Game is an object of cricket class
- New keyword creates object Game
- Game is a class and cricket is an object
- Game and cricket are objects
Show answer
ICSE 2025 board paper · 1 mark
Which of the following is user defined data type? | 1. array | 3. class | |---|---| | 2. double | 4. boolean |
- only 1
- 1 and 3
- only 2
- only 4
Show answer
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
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.