Skip to content
Computer ApplicationsICSE Class 10 · Chapter 10

Class as the Basis of All Computation ICSE Class 10 Java

Updated 14 October 2026 · Fact-checked

In Java every computation happens inside classes. A class bundles member variables (which define an object's state) and member methods (which define its behaviour); objects are instances created from it. Primitive types hold single values, while classes are composite types built from them. ICSE Class 10 tests these ideas and class-based programs such as slab bills.

What Class as the Basis of All Computation is about

The first question of Section B in both 2024 (courier charges) and 2025 (cloud storage) was a class-based program: given a class name, member variables and member methods, write accept(), calculate() and display() and a main() that creates an object and calls them. Examiners deducted marks for changing the given names, declaring member variables inside methods, wrong slab calculations, and not creating the object in main(). A 2024 assertion-reason also tested static and instance members.

The syllabus asks for objects encapsulating state and behaviour, member variables and member methods, classes as abstractions for sets of objects and as object factories, primitive and composite data types and their declarations, and objects as instances of a class, with real-life examples.

Weightage: CISCE publishes no chapter weightage. Section A (40 marks) is compulsory: 1-mark MCQs and 2-mark short answers including output and error questions; in Section B you answer any four of six 15-mark programming questions written in Java.Source: CISCE ICSE Computer Applications (661) specimen paper structure for 2027

Key concepts

Member variables and member methods

Member variables (data members, fields, attributes) are declared inside the class but outside all methods. They define the state of each object and are available to every method of the class. Member methods (functions) define behaviour: what an object can do with its data.

class Account
{
double balance; // member variable (state)
void deposit(double amt) // member method (behaviour)
{
balance = balance + amt;
}
}

Local variables are declared inside a method; they exist only while the method runs and are not shared with other methods. A common board error is declaring the member variables again inside accept(), which creates new local variables and leaves the real members unchanged.

Worked example

(2 marks) What is the difference between a member variable and a local variable?

Try it first, then show the solutionSolution
  1. Member variable: declared in the class outside methods; available to all methods; part of the object's state - 1 mark.
  2. Local variable: declared inside a method; exists only during that method - 1 mark.

Answer: A member variable is declared inside the class but outside every method, belongs to the object and can be used by all its methods; a local variable is declared inside a method and exists only while that method runs.

Instance variables and class (static) variables

Instance variables (non-static members): each object gets its own copy. Two Student objects have their own names.
Class variables (static members): declared with static; only one copy is shared by all objects of the class. Used for counts and common values.

class Visitor
{
static int total; // shared
int id; // one per object
void enter()
{
total++;
id = total;
}
public static void main(String args[])
{
Visitor a = new Visitor();
Visitor b = new Visitor();
a.enter();
b.enter();
System.out.println(a.id + " " + b.id + " " + Visitor.total);
}
}
Output: 1 2 2

Rules: a static method can directly use only static members; to use instance members it needs an object (that is why main creates an object). An instance (non-static) method can use both static and instance members.

Worked example

(2 marks) Why can't a static method directly use an instance variable?

Try it first, then show the solutionSolution
  1. A static method belongs to the class and can run without any object - 1 mark.
  2. Instance variables exist only inside objects, so there is no object whose copy it could use - 1 mark.

Answer: A static method belongs to the class and may be called without creating any object, while an instance variable exists separately in each object; without an object there is no copy to refer to, so it must create or be given an object first.

Primitive and composite data types

Primitive (built-in) types: byte, short, int, long, float, double, char, boolean. They hold a single value of fixed size and are predefined by Java.
Composite (non-primitive, reference) types: classes, arrays, interfaces and String. They are built from primitive and other types, may be defined by the user, and their variables hold references to objects.

Declarations: int count = 0; (primitive) and Student s = new Student(); (composite: the variable s refers to an object created with new).

Differences: (1) predefined vs user-defined; (2) single value vs group of values and methods; (3) fixed size vs size depends on members; (4) stored directly vs accessed through a reference; (5) default value 0/false vs null.

Worked example

(2 marks) Give two differences between primitive and composite data types.

Try it first, then show the solutionSolution
  1. Primitive types are predefined by Java; composite types are built from them, often by the user - 1 mark.
  2. Primitive variables hold one value directly; composite variables refer to objects that may hold many values and methods - 1 mark.

Answer: (1) Primitive types such as int are predefined by Java, whereas composite types such as a class are built from primitive types, often by the user. (2) A primitive variable holds a single value directly, whereas a composite variable refers to an object that can hold several values and methods.

Class as abstraction and object factory

A class is an abstraction for a set of similar objects: it keeps only the features relevant to the program. A class Patient in hospital software may keep name, age and illness, ignoring hair colour. From this one description, any number of objects can be produced (object factory), each an instance with its own state.

Real-life analogy: 'Mobile phone' is the class; your phone and your friend's phone are objects. They share features (screen, battery, call()) but have different states (different contacts, charge levels).

Worked example

(2 marks) Explain 'objects are instances of a class' with an example.

Try it first, then show the solutionSolution
  1. A class is a general description; an instance is one particular object made from it - 1 mark.
  2. Example: class Car; myCar and taxi are instances with their own colours and speeds - 1 mark.

Answer: An instance is a particular object created from the general description in a class. For class Car, Car myCar = new Car(); and Car taxi = new Car(); create two instances, each with its own colour and speed.

Writing a class-based Section B program

Board pattern: 'Define a class with the following specifications: class name, member variables, member methods.' Steps:
(1) Use exactly the class, variable and method names given.
(2) Declare member variables in the class, outside methods (not inside accept()).
(3) accept(): create a Scanner and read each member variable with the right method.
(4) calculate(): use an if-else-if ladder for slabs; store the result in the member variable.
(5) display(): print every member variable asked for, with labels.
(6) main(): create an object and call accept(), calculate() and display() in order.
(7) Write a variable description or comments.

Worked example

(2 marks) A student writes void accept() { Scanner sc = new Scanner(System.in); double weight = sc.nextDouble(); } for a member variable weight. What goes wrong?

Try it first, then show the solutionSolution
  1. double weight inside accept() declares a new local variable that hides the member variable - 1 mark.
  2. The member weight stays 0.0, so calculate() uses 0.0; write weight = sc.nextDouble(); instead - 1 mark.

Answer: Redeclaring weight inside accept() creates a local variable; the member variable weight remains 0.0, so later calculations are wrong. Write weight = sc.nextDouble(); without the type.

Class as the Basis of All Computation in real life

Each concept, met in an everyday situation. Read the situation, answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Static (shared) vs instance members

Suppose every train coach has its own number of passengers, but there is one display at the station showing the total passengers on the whole train.

Which would be static and which an instance variable?

Try it first, then show the solutionSolution
  1. Each coach has its own count: instance variable.
  2. One shared total for the whole train: static (class) variable.

Answer: passengers in each Coach object is an instance variable; totalPassengers shared by all coaches is a static variable.

Memory hook: Static is shared; instance is mine.

Slab-based class

Imagine a taxi app that charges ₹25 per km for the first 5 km, ₹18 per km for the next 10 km and ₹12 per km beyond 15 km.

Find the fare for 22 km.

Try it first, then show the solutionSolution
  1. First 5 km: 5 × 25 = 125.
  2. Next 10 km: 10 × 18 = 180.
  3. Remaining 7 km: 7 × 12 = 84; total 389.

Answer: ₹389.

Memory hook: Fill each slab before moving to the next.

Class as abstraction

Suppose a school library app needs to model books; a book has a weight, a smell and a colour, but the app needs only title, author and availability.

What should the Book class contain, and which idea is this?

Try it first, then show the solutionSolution
  1. Keep only features relevant to the program.
  2. Ignore weight, smell, colour.
  3. This is abstraction.

Answer: class Book with title, author and isAvailable, and methods such as issue() and returnBook(): a class is an abstraction keeping only relevant features.

Memory hook: Model what matters, ignore the rest.

Topics in this chapter

Class as the Basis of All Computation: syntax and key facts

Class template
class Name { member variables; void accept() { } void calculate() { } void display() { } main() { Name ob = new Name(); ob.accept(); ob.calculate(); ob.display(); } }
Use the given names exactly.
Static rule
static method → static members directly; instance members only through an object
Instance methods can use both.
Slab template
if (x <= a) c = x * r1; else if (x <= b) c = a * r1 + (x - a) * r2; else c = a * r1 + (b - a) * r2 + (x - b) * r3;

How the board asks Class as the Basis of All Computation

The question patterns to expect, and the method that works for each.

Question typeHow it is askedMethod
MCQ / assertion-reason (Section A)Static and instance access (2024); identify member variables and methods.Remember static members are shared and static methods need an object for instance members.
Short answer (2 marks)Primitive vs composite; instance vs class variable; member vs local variable.Two matched points with a code example.
Program (15 marks)Courier charges by weight and type (2024); cloud storage bill by tiers (2025).Names exactly as given; members outside methods; slab ladder; display all members; main with object.

Tricks to remember Class as the Basis of All Computation

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • A-C-D-M

    Accept, Calculate, Display, Main: the four parts of every class program.

    Use it when: Section B structure.

  • Static = one for all

    One static copy for all objects; one instance copy for each object.

    Use it when: Static vs instance.

Class as the Basis of All Computation: board-level solved questions

Ordered from board level to HOTS. Cover the solution, write your own, then compare step by step.

Example 1: Shared counter · 1 mark · MCQHarder board level

What is printed by the Visitor program (static total, instance id) after a.enter(); b.enter(); System.out.println(a.id + " " + b.id + " " + Visitor.total);?
(a) 1 1 1
(b) 1 2 2
(c) 2 2 2
(d) 1 2 1

Try it first, then show the solutionSolution
  1. a.enter(): total = 1, a.id = 1. b.enter(): total = 2, b.id = 2. total is shared.

Answer: (b) 1 2 2

Example 2: Composite type · 1 mark · MCQBoard level

Which of these is a composite data type?
(a) char
(b) boolean
(c) a class Student
(d) long

Try it first, then show the solutionSolution
  1. A class combines several members; the others are primitive.

Answer: (c) a class Student

Example 3: Assertion and reason: static access · 1 mark · Assertion-reasonHOTS / competency

Assertion (A): A static method can directly access instance variables of its class.
Reason (R): A static method can be called without creating an object of the class.
(a) Both A and R are true and R is the correct explanation of A
(b) Both A and R are true but R is not the correct explanation of A
(c) A is true but R is false
(d) A is false but R is true

Try it first, then show the solutionSolution
  1. A is false: without an object there is no instance variable to use.
  2. R is true: static methods belong to the class.

Answer: (d) A is false but R is true

Example 4: Member vs local · 2 marks · Very short answerBoard level

Identify the member variables and local variables:
class Shop
{
String item;
int qty;
void bill()
{
double rate = 40.0;
double amt = qty * rate;
System.out.println(item + " " + amt);
}
}

Try it first, then show the solutionSolution
  1. Declared in the class outside methods: item, qty.
  2. Declared inside bill(): rate, amt.

Answer: Member variables: item and qty. Local variables: rate and amt.

Example 5: Find the error · 2 marks · Very short answerHarder board level

Why does this not compile? Correct it.
class Test
{
int x = 5;
public static void main(String args[])
{
System.out.println(x);
}
}

Try it first, then show the solutionSolution
  1. main is static; x is an instance variable, so it cannot be used directly.
  2. Create an object: Test t = new Test(); System.out.println(t.x);

Answer: A static method cannot directly use the instance variable x. Correct:
Test t = new Test();
System.out.println(t.x);
Output: 5

Example 6: Taxi fare class (Section B) · 15 marks · Long answerHarder board level

Define a class Taxi with member variables: String name (passenger), double distance (km), double fare. Member methods: void accept() to input name and distance; void calculate() to compute fare: first 5 km ₹25 per km, next 10 km ₹18 per km, above 15 km ₹12 per km; void display() to print name, distance and fare. Write main() to create an object and call the methods.

Try it first, then show the solutionSolution
  1. import java.util.Scanner;
    class Taxi
    {
    String name;
    double distance, fare;
    void accept()
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Name: ");
    name = sc.nextLine();
    System.out.print("Distance (km): ");
    distance = sc.nextDouble();
    }
  2. void calculate()
    {
    if (distance <= 5)
    fare = distance * 25;
    else if (distance <= 15)
    fare = 5 * 25 + (distance - 5) * 18;
    else
    fare = 5 * 25 + 10 * 18 + (distance - 15) * 12;
    }
  3. void display()
    {
    System.out.println("Name: " + name);
    System.out.println("Distance: " + distance + " km");
    System.out.println("Fare: Rs " + fare);
    }
  4. public static void main(String args[])
    {
    Taxi t = new Taxi();
    t.accept();
    t.calculate();
    t.display();
    }
    }
  5. Trace 22 km: 125 + 180 + 7.0 × 12 = 389.0. Trace 12 km: 125 + 7.0 × 18 = 251.0. Trace 4 km: 100.0.

Answer: Sample run:
Name: Kiran
Distance (km): 22
Name: Kiran
Distance: 22.0 km
Fare: Rs 389.0

Example 7: Storage plan class · 15 marks · Long answerHOTS / competency

Define a class Storage with int accNo, int space (GB) and double bill. accept() reads accNo and space; calculate() charges ₹15 per GB for the first 15 GB, ₹13 per GB for the next 15 GB and ₹11 per GB beyond 30 GB, and adds 18% tax if the charge exceeds ₹500; display() prints all three. Write main().

Try it first, then show the solutionSolution
  1. import java.util.Scanner;
    class Storage
    {
    int accNo, space;
    double bill;
    void accept()
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Account number and space: ");
    accNo = sc.nextInt();
    space = sc.nextInt();
    }
  2. 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;
    if (bill > 500)
    bill = bill + bill * 18 / 100;
    }
  3. void display()
    {
    System.out.println("Account: " + accNo);
    System.out.println("Space: " + space + " GB");
    System.out.println("Bill: " + bill);
    }
    public static void main(String args[])
    {
    Storage s = new Storage();
    s.accept();
    s.calculate();
    s.display();
    }
    }
  4. Trace 40 GB: 225 + 195 + 10 × 11 = 530; 530 > 500 so tax 95.4; bill = 625.4.
  5. Trace 20 GB: 225 + 5 × 13 = 290 (no tax); bill = 290.0. (bill is double, so 290 prints as 290.0.)

Answer: Sample run:
Account number and space: 1201 40
Account: 1201
Space: 40 GB
Bill: 625.4

Case-study practice (Section B style)

Read the situation, then answer every part. In the board paper this is a 10-mark question split into 2 + 3 + 5 marks.

Reviewing a courier program

Imagine a student's answer for class courier (name, weight, address, bill, type): he names the class Courier, declares double weight; again inside accept(), reads type with sc.nextLine(), computes the bill correctly, prints only the bill in print(), and his main() is empty.

  1. (i) · 2 marks

    Why will the examiner deduct marks for the class name and for 'double weight' inside accept()?

    Answer

    Answer: Java is case sensitive and the question asked for courier, so names must match exactly. Redeclaring weight inside accept() makes a local variable, leaving the member weight at 0.0.

    1 mark each.

  2. (ii) · 3 marks

    How should type ('D' or 'I') be read, and what is missing in print()?

    Answer

    Answer: type = sc.next().charAt(0); print() must print all member variables asked for (name, weight, address, type and bill), not just the bill.

    Input statement 1 mark; printing every member 2 marks.

  3. (iii) · 5 marks

    Write the missing main() and explain why it is needed.

    Answer

    Answer: public static void main(String args[])
    {
    courier c = new courier();
    c.accept();
    c.calculate();
    c.print();
    }
    (using the method names given in the question). Without main() creating an object and calling the methods, the instance methods never run, and examiners award marks for the object creation and the calls.

    Code 4 marks; reason 1 mark.

Where the marks are

How a typical answer is split into step marks. Show every step: a right final answer alone rarely earns full marks.

Distinguish between instance and class variables. (2 marks) (2 marks)

StepMarks
Instance: separate copy per object.1
Class/static: one shared copy, declared static.1

Class-based slab program (Taxi). (15 marks) (15 marks)

StepMarks
Class name and member variables as given, outside methods.2
accept() with Scanner and correct input methods.3
calculate(): correct slab ladder and boundaries.4
display() printing all required members.2
main(): object creation and calls in order.3
Variable description / comments.1

Where students lose marks in Class as the Basis of All Computation

The slips examiners see most often, and what to write instead.

  • Mistake: Not using the names given in the question

    Both the 2024 and 2025 examiners reported changed class, variable or method names.

    Do this: Copy every name exactly, including case.

    Usually costs: 1 to 2 marks of 15.

  • Mistake: Declaring member variables inside accept()

    Reported by the 2025 examiners in the CloudStorage program.

    Do this: Declare members once in the class; inside methods assign without a type.

    Usually costs: 2 to 3 marks.

  • Mistake: Wrong slab logic or accepting the bill as input

    In 2025 candidates did not use the tier method, or accepted the bill instead of calculating it.

    Do this: Compute the bill in calculate() using the slabs given.

    Usually costs: 4 to 6 marks.

  • Mistake: Not creating an object or calling methods

    Reported in both 2024 and 2025.

    Do this: main(): ClassName ob = new ClassName(); then call each method.

    Usually costs: 2 to 3 marks.

  • Mistake: Confusion over static access

    The 2024 examiners found candidates unclear about static members and accessibility.

    Do this: Static methods use instance members only through an object.

    Usually costs: 1 mark.

Practice questions on Class as the Basis of All Computation

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    Variables declared inside a class but outside all methods are called:
    (a) local variables
    (b) member variables
    (c) parameters
    (d) constants

    Hint

    Members.

    Answer

    (b) member variables

  2. Q2 · 1 mark · MCQBoard level

    A variable shared by all objects of a class is declared with the keyword:
    (a) final
    (b) static
    (c) new
    (d) void

    Hint

    One copy.

    Answer

    (b) static

  3. Q3 · 1 mark · MCQHarder board level

    What is the default value of a String member variable that has not been assigned?
    (a) ""
    (b) 0
    (c) null
    (d) error

    Hint

    Reference type.

    Answer

    (c) null

  4. Q4 · 2 marks · Very short answerBoard level

    Distinguish between an instance variable and a class (static) variable.

    Hint

    Copies.

    Answer

    Each object has its own copy of an instance variable, whereas a class variable, declared static, has a single copy shared by all objects of the class and can be used with the class name.

  5. Q5 · 2 marks · Short answerHOTS / competency

    Give the output:
    class P
    {
    static int s = 0;
    int t = 0;
    void inc() { s++; t++; }
    public static void main(String args[])
    {
    P a = new P(), b = new P();
    a.inc(); a.inc(); b.inc();
    System.out.println(a.t + " " + b.t + " " + s);
    }
    }

    Hint

    s shared, t separate.

    Answer

    2 1 3

  6. Q6 · 2 marks · Very short answerHarder board level

    Why is a class called an abstraction for a set of objects?

    Hint

    Relevant features.

    Answer

    Because it describes only the common, relevant features (variables and methods) of a group of similar objects, ignoring details that do not matter to the program; each object is a particular case of that description.

  7. Q7 · 15 marks · Long answerBoard level

    Define a class Parking with member variables vno (int), hours (int) and bill (double). accept() reads them; calculate() charges ₹30 for the first hour and ₹20 for each additional hour; display() prints vno, hours and bill. Write main().

    Hint

    First hour is a flat charge.

    Answer

    import java.util.Scanner;
    class Parking
    {
    int vno, hours;
    double bill;
    void accept()
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Vehicle number and hours: ");
    vno = sc.nextInt();
    hours = sc.nextInt();
    }
    void calculate()
    {
    if (hours <= 1)
    bill = 30;
    else
    bill = 30 + (hours - 1) * 20;
    }
    void display()
    {
    System.out.println(vno + " " + hours + " " + bill);
    }
    public static void main(String args[])
    {
    Parking p = new Parking();
    p.accept();
    p.calculate();
    p.display();
    }
    }
    Trace 4521, 5 hours: 30 + 4 × 20 = 110.0; prints 4521 5 110.0.

  8. Q8 · 2 marks · Short answerHOTS / competency

    In the Storage program, what is the bill for 31 GB? Show the working.

    Hint

    Third slab then tax.

    Answer

    225 + 195 + 1 × 11 = 431; not more than 500, so no tax; bill = 431.0.

  9. Q9 · 2 marks · Very short answerHarder board level

    State two differences between a class and a primitive data type.

    Hint

    Methods; definer.

    Answer

    (1) A class can contain several variables of different types together with methods; a primitive holds one value and has no methods. (2) Primitive types are predefined by Java; classes can be defined by the user.

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.Where are member variables declared?Show answer

    Inside the class, outside all methods.

  2. 2.How many copies of a static variable exist?Show answer

    One, shared by all objects.

  3. 3.Is String primitive or composite?Show answer

    Composite (a class).

  4. 4.What must main() do in a class program?Show answer

    Create an object and call the methods.

  5. 5.Default value of an int member?Show answer

    0

Best order to study it

  1. Member variables vs local variables; member methods.
  2. Instance vs static members and access rules.
  3. Primitive vs composite types.
  4. Class as abstraction and object factory.
  5. Practise two slab-based class programs.

Quick revision checklist

The night before the exam: can you do each of these without looking?

  • Class = member variables (state) + member methods (behaviour).
  • Instance: one per object; static: one shared.
  • Static methods need an object for instance members.
  • Primitive: single predefined value; composite: classes, arrays, String.
  • Section B: given names, members outside methods, accept-calculate-display, main with object.

Class as the Basis of All Computation: frequently asked questions

Must main() be inside the same class?

In ICSE answers, yes: write main() inside the class asked for, creating an object of it.

Can I print the bill inside calculate()?

Only if the question says so. If a display() method is specified, printing belongs there.

Do I need to write a variable description table in the exam?

It is not always demanded, but comments explaining variables help the examiner and are expected in school assignments.

Based on: CISCE ICSE 2027 Computer Applications syllabus; CISCE Analysis of Pupil Performance ICSE 2025: Computer Applications (with the 2025 board paper)