Follow Us
Select Medium / माध्यम चुनें:
Eng (English) Hindi (हिन्दी)
ICSE • Class X • Information Technology • Ch 2
Estimated Time: 45 Mins
Study Progress: In Progress

Class as the Basis of all Computation

Mastering classes and objects as the fundamental computational units in Java. Explores object state and behaviour, class as an object factory and user-defined data type, variable scopes (instance, static, local), Heap and Stack memory architectures, object lifecycle, and complete ICSE class design patterns.

Why This Chapter Matters

Mastering classes and objects as the fundamental computational units in Java. Explores object state and behaviour, class as an object factory and user-defined data type, variable scopes (instance, static, local), Heap and Stack memory architectures, object lifecycle, and complete ICSE class design patterns.

Chapter Roadmap & Progression

1 1. Objects and Classes: State, Beha...
2 2. Class as a User-Defined Composit...
3 3. Variable Taxonomy: Instance, Cla...
4 4. Memory Allocation: Stack vs Heap...
5 5. The Dot Operator (.) & Member Ac...
6 6. Life Cycle of an Object & Garbag...
7 7. Complete ICSE Board Class Design...
8 8. ICSE Class Design Blueprint: Com...

Complete Concept Guide (100% Curriculum Coverage)

1. Objects and Classes: State, Behaviour & Object Factory Paradigm

Fundamental Concepts
The Object as the Primary Computational Unit:

In Java, computation revolves entirely around objects. An object is a real-world entity or abstract concept that possesses three quintessential characteristics:

  • State (Attributes / Data Members): The intrinsic properties, characteristics, or values held by the object at any given time. For an Account object, state includes accountNumber, holderName, and balance.
  • Behaviour (Functions / Member Methods): The operations, transformations, or actions that an object can perform or have performed upon it. For Account, behaviour includes deposit(), withdraw(), and checkBalance().
  • Identity (Memory Address): A unique, system-level identification distinguishing the object from all other objects in memory, even if two objects possess identical state values.
The Class as an Object Factory (Blueprint):

A class is an abstract template, blueprint, or specification from which individual objects are fabricated. Just as an architectural blueprint defines the dimensions and structure of a house without itself being a physical shelter, a class defines the fields and methods without allocating memory for actual data until an object is instantiated. Hence, a class is famously known as an "Object Factory".

2. Class as a User-Defined Composite Data Type

Composite Data Types
Primitive vs User-Defined Composite Types:

While Java provides 8 built-in primitive data types (such as int, double, char), real-world systems require complex structures combining multiple related attributes. A class acts as a User-Defined Data Type (UDT) or composite type.

Criterion Primitive Data Types User-Defined Class Types
Definition Built into the Java core language specification. Designed and defined by the software developer.
Memory Storage Stored directly on the runtime Call Stack; holds actual bit values. Reference resides on Stack; actual object attributes reside on the Heap.
Composition Atomic; cannot be decomposed into smaller units. Composite; bundles multiple primitive and reference types together.
Default Value 0, 0.0, false, '\u0000'. null (indicating no allocated Heap memory).
Method Invocation Cannot invoke methods (no dot operator). Can invoke member methods via the dot operator (obj.method()).

3. Variable Taxonomy: Instance, Class (Static) & Local Variables

Variable Architecture
Three Tiers of Variables in Java:

Understanding variable scope, lifetime, and storage location is one of the most frequently tested concepts in ICSE Computer Applications.

Attribute Instance Variables (Non-Static) Class Variables (Static) Local Variables
Declaration Location Inside class, outside all methods. Inside class, outside methods, with static keyword. Inside a method, constructor, or block {}.
Memory Location Heap Memory (inside object block). Class / Method Area (Metaspace). Call Stack Memory (method frame).
Lifetime / Duration Created when object is created via new; destroyed by GC. Created when class is loaded into JVM; destroyed on program exit. Created upon method invocation; destroyed when method exits.
Default Initialization Automatically initialized to default values (0, null, false). Automatically initialized to default values. NO default initialization; must be initialized before read!
Copies in Memory One independent copy per instantiated object. Exactly ONE copy shared by ALL objects. One copy per active method invocation thread.

4. Memory Allocation: Stack vs Heap & The 'new' Operator

Memory Architecture
The Anatomy of Object Instantiation:

Consider the classic declaration and instantiation statement:

Student s1 = new Student();

This single statement triggers three synchronized memory events:

  1. Declaration (Student s1;): Allocates a reference variable named s1 on the Call Stack. At this stage, s1 contains no address (it evaluates to null).
  2. Dynamic Allocation (new): The new keyword calculates the exact byte size required for all instance variables of the Student class and allocates a contiguous memory block on the Heap. It returns the 64-bit hexadecimal memory address of this block.
  3. Initialization (Student()): The constructor is executed, populating the newly allocated Heap fields with default or user-specified initial values.
  4. Assignment (=): The returned Heap memory address is assigned to reference variable s1 on the Stack.
NullPointerException Trap: Attempting to access an instance variable or method through an uninitialized reference (e.g., Student s; s.display();) results in a fatal runtime NullPointerException because the reference points to memory address zero.

5. The Dot Operator (.) & Member Access Mechanics

Member Access
Syntax and Role of the Dot Operator:

The dot operator (.) is the member access operator in Java. It establishes a dereference link between a reference variable on the Stack and the concrete data fields or member methods living inside the Heap object.

// Accessing instance variables:
s1.name = "Aarav Sharma";
s1.marks = 94.5;

// Invoking member methods:
s1.calculateGrade();
s1.displayReport();
Static Member Access via Class Name:

Because static variables and static methods belong to the entire class rather than any individual object, they should be invoked directly using the Class Name rather than an object reference:

// Recommended best practice:
Student.schoolName = "St. Xavier's School";
double root = Math.sqrt(144.0); // Math is the class name!

6. Life Cycle of an Object & Garbage Collection

Object Lifecycle
The Four Stages of an Object's Life:
  1. Declaration: Binding a variable name to a class type on the Stack.
  2. Instantiation: Physical creation of the object in Heap memory using the new operator.
  3. Initialization: Execution of constructors to assign meaningful state to instance fields.
  4. Destruction & Garbage Collection: When an object is no longer reachable by any active reference variable (e.g., s1 = null; or reassignment s1 = s2;), it becomes eligible for Garbage Collection (GC). The JVM's automatic garbage collector periodically reclaims orphaned Heap memory.

7. Complete ICSE Board Class Design Blueprint: Student Report Card

Board Class Design
Model Program 1: Complete Class Architecture with Methods
import java.util.Scanner;

public class Student {
    // 1. Instance Variables (Data Members)
    private String name;
    private int rollNo;
    private double marks1, marks2, marks3;
    private double total, average;
    private char grade;

    // 2. Member Method to input data
    public void accept() {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter Student Name: ");
        name = sc.nextLine();
        System.out.print("Enter Roll Number: ");
        rollNo = sc.nextInt();
        System.out.print("Enter Marks in 3 Subjects: ");
        marks1 = sc.nextDouble();
        marks2 = sc.nextDouble();
        marks3 = sc.nextDouble();
    }

    // 3. Member Method to compute results
    public void compute() {
        total = marks1 + marks2 + marks3;
        average = total / 3.0;
        if (average >= 90) grade = 'A';
        else if (average >= 75) grade = 'B';
        else if (average >= 60) grade = 'C';
        else if (average >= 40) grade = 'D';
        else grade = 'F';
    }

    // 4. Member Method to display formatted output
    public void display() {
        System.out.println("----- Student Report Card -----");
        System.out.println("Roll No : " + rollNo);
        System.out.println("Name    : " + name);
        System.out.println("Total   : " + total + " / 300");
        System.out.println("Average : " + average + "%");
        System.out.println("Grade   : " + grade);
    }

    // 5. Main method instantiating object
    public static void main(String[] args) {
        Student obj = new Student(); // Object creation
        obj.accept();                // Invoking methods via dot operator
        obj.compute();
        obj.display();
    }
}

8. ICSE Class Design Blueprint: Commercial Electric Bill Calculator

Commercial Class Design
Model Program 2: Real-World Tariff Calculation Class
import java.util.Scanner;

public class ElectricBill {
    private String n;      // Consumer Name
    private int units;     // Units Consumed
    private double bill;   // Bill Amount

    public void accept() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Consumer Name: ");
        n = in.nextLine();
        System.out.print("Enter Units Consumed: ");
        units = in.nextInt();
    }

    public void calculate() {
        // Slab tariff logic
        if (units <= 100) {
            bill = units * 2.0;
        } else if (units <= 300) {
            bill = (100 * 2.0) + ((units - 100) * 3.0);
        } else {
            bill = (100 * 2.0) + (200 * 3.0) + ((units - 300) * 5.0);
            // Surcharge of 2.5% if units exceed 300
            double surcharge = bill * 0.025;
            bill += surcharge;
        }
    }

    public void print() {
        System.out.println("=================================");
        System.out.println("ELECTRICITY CONSUMPTION INVOICE");
        System.out.println("Consumer Name  : " + n);
        System.out.println("Units Consumed : " + units);
        System.out.println("Net Payable    : Rs. " + bill);
        System.out.println("=================================");
    }

    public static void main(String[] args) {
        ElectricBill eb = new ElectricBill();
        eb.accept();
        eb.calculate();
        eb.print();
    }
}

Common Misconceptions & Examiner Traps

Common Misconception

Reading a local variable before explicitly initializing it

Scientific Reality & Correction

Local variables do not receive default values. Attempting to use an uninitialized local variable causes a compile-time error: 'variable might not have been initialized'.

Common Misconception

Calling non-static methods directly from static main() without an object reference

Scientific Reality & Correction

Non-static instance methods require an object. You must instantiate the class ('Student s = new Student();') and invoke via the dot operator ('s.display();').

Common Misconception

Believing a class declaration allocates memory for instance data

Scientific Reality & Correction

A class is merely a blueprint. Memory for instance data is ONLY allocated when the 'new' operator is executed at runtime.

Common Misconception

Invoking static variables through an object reference rather than the Class name

Scientific Reality & Correction

While legal, calling static members via object references is bad practice. Always access static members via the Class Name (e.g., 'Student.schoolName').

Architectural Blueprint : Class as the Basis of all Computation

ICSE Class 10 Java : Class Blueprint & Object Memory Architecture Class : The Abstract Blueprint (Factory) • Definition: User-defined composite data type; template for objects. • State (Attributes / Data Members): Instance variables (e.g. name, rollNo, marks). • Behaviour (Member Methods): Functions operating on state (e.g. input(), calculate(), display()). Memory: Exists in Method Area / Metaspace. new Object : Concrete Instance (Heap Memory) • Instantiation: Student s1 = new Student(); • Stack Reference: s1 holds 64-bit memory address pointer on Stack. • Heap Allocation: Distinct memory block allocated for instance variables. Dot Operator (.): s1.calculate(); calls method. Variable Scope & Memory Allocation Architecture • Instance Variables: Declared inside class, outside methods. Allocated in HEAP when object is instantiated; unique to each object. • Class (Static) Variables: Declared with static keyword. Single copy shared across ALL objects in Class Memory. • Local Variables: Declared inside method/block. Allocated on STACK; created upon method entry, destroyed upon exit.

Chapter Summary & 10 Key Takeaways

Takeaway 1
A Class is a user-defined composite blueprint (factory) defining state and behaviour; an Object is a concrete, tangible instance of that class.
Takeaway 2
An object possesses three fundamental characteristics: State (data attributes), Behaviour (member methods), and Identity (unique memory address).
Takeaway 3
Classes serve as User-Defined Data Types (Composite Types), allowing programmers to group heterogeneous primitive types into a single conceptual entity.
Takeaway 4
The `new` operator dynamically allocates memory on the Heap for the object's instance variables and invokes the appropriate constructor.
Takeaway 5
A reference variable declared as `Student s;` resides on the Stack and stores memory address pointers; it remains `null` until initialized via `new`.
Takeaway 6
Instance variables belong to an individual object and receive default values (e.g., 0 for numeric, null for reference, false for boolean) upon instantiation.
Takeaway 7
Static (class) variables are declared with the `static` keyword; a single memory copy is shared by all instances of the class.
Takeaway 8
Local variables are defined within a method block, live only during method execution on the Stack frame, and MUST be explicitly initialized before use.
Takeaway 9
The dot operator (`.`) is the member access operator in Java, used to reference instance variables (`obj.field`) and invoke methods (`obj.method()`).
Takeaway 10
Garbage collection in Java runs automatically in the background, freeing Heap memory occupied by unreferenced objects whose reference count drops to zero.

Check Your Understanding (Diagnostic Practice Questions)

Diagnostic questions testing core conceptual clarity. Answers are hidden initially — solve each problem first, then click to reveal the step-by-step verified solution.

1
Why is a class known as an 'Object Factory' and a 'Composite User-Defined Data Type'?
Reveal Answer & Explanation
Answer: A class is called an 'Object Factory' because it serves as an architectural template or blueprint from which any number of discrete, concrete object instances can be manufactured with identical structural fields and behaviours. It is termed a 'Composite User-Defined Data Type' because it enables developers to construct custom high-level data types that combine diverse primitive types (integers, floating-point numbers, characters) and reference types into a unified entity representing real-world business models.
2
Differentiate between an Object and a Class with respect to memory allocation.
Reveal Answer & Explanation
Answer: A Class is an abstract software construct; declaring a class does not allocate Heap memory for data fields (it only occupies space in the JVM Metaspace/Method Area for class definitions and static members). An Object is a concrete physical entity created dynamically at runtime; executing 'new ClassName()' dynamically allocates a unique, contiguous memory block on the Heap to store the specific instance variables of that object.
3
What is the role of the 'new' operator during object creation in Java?
Reveal Answer & Explanation
Answer: The 'new' operator performs dynamic memory allocation. It calculates the exact amount of Heap memory required for the specified class, allocates that contiguous memory block, initializes fields with default values, invokes the appropriate class constructor to set initial state, and finally returns the 64-bit memory reference address of the newly fabricated Heap object to the Stack variable.
4
Distinguish between Instance Variables and Local Variables in terms of declaration, scope, and default values.
Reveal Answer & Explanation
Answer:
  1. Declaration: Instance variables are declared within the class body outside all methods; local variables are declared inside a specific method, constructor, or block. 2. Scope & Lifetime: Instance variables exist as long as the containing object exists in Heap memory; local variables exist only while the enclosing method executes on the Stack frame. 3. Default Values: Instance variables are automatically initialized to language defaults (0, 0.0, false, null); local variables receive NO default values and cause compile-time errors if read before explicit initialization.

5
What happens when an object reference variable is assigned 'null'?
Reveal Answer & Explanation
Answer: Assigning 'null' to an object reference (e.g., 's1 = null;') severs the pointer link between the reference variable on the Stack and the object residing on the Heap. If no other active reference points to that Heap object, the object becomes unreachable ('orphaned') and becomes eligible for automatic memory deallocation by the Java Garbage Collector.
6
How does a static (class) variable differ from a non-static (instance) variable?
Reveal Answer & Explanation
Answer: A static variable (declared with the 'static' keyword) belongs to the class itself; exactly ONE single copy of the variable exists in memory (in the Metaspace/Method Area) and is shared across all instances of that class. Modifying a static variable in one object affects all other objects. In contrast, an instance variable belongs to an individual object; every instantiated object receives its own independent, isolated copy stored on the Heap.
7
What is the purpose of the dot operator (.) in Java?
Reveal Answer & Explanation
Answer: The dot operator (.) is the member access or dereferencing operator in Java. It allows a program to access instance variables (e.g., 'objectRef.variableName') and invoke member methods (e.g., 'objectRef.methodName()') belonging to an object whose address is held by the reference variable.
8
Explain the concept of Garbage Collection in Java. Why does Java not require explicit memory deallocation operators like C++ delete?
Reveal Answer & Explanation
Answer: Garbage Collection is an automated background memory management process executed by the JVM. It constantly tracks object reachability; when an object no longer has any active references pointing to it from the Stack, the Garbage Collector identifies it as dead memory and silently reclaims its Heap space. This eliminates common C/C++ memory corruption vulnerabilities such as memory leaks, dangling pointers, and double-free errors.
Finished Studying This Chapter?
READY TO PRACTICE?

Timed CBT Practice Tests (Exam Simulator)

Put your concepts to the test with official curriculum-aligned Foundation and Advanced practice tests. Get instant accuracy scores, time metrics, and step-by-step verified explanations.