ICSE Class 10 · Computer Applications (Java) · Encapsulation 2027

Encapsulation for ICSE Class 10: who can see what, and for how long.

Encapsulation in ICSE Class 10 comes down to two questions: which classes can reach a member, and how long a variable lives. The first is answered by the access specifiers, the second by the scope of variables. This page gives the one-line definitions, an access table we checked with the Java compiler across two packages, data hiding with getters and setters, the four kinds of variable, and a Section B class built on private data. In our live mini batch these rules are traced, compiled and written by hand every week.

Live online · access table checked with javac · four kinds of variable · one Section B class with private data · first class free

Start here

Courses where encapsulation is practised

The ICSE Java course where the mini batch writes classes with private data every week, the Class 11 and 12 Computer Science course where encapsulation grows into inheritance, and the data structures course for students who want to see why real libraries hide their fields.

Ans. The short version

Encapsulation in ICSE Class 10 means wrapping a class's data and the methods that use it into one unit, and controlling access to that data. Java does it with access specifiers: private (same class only), default with no keyword (same package), protected (same package and subclasses) and public (everywhere). Making data private and reaching it only through public methods is called data hiding. The same 2027 syllabus unit covers the scope of variables: class, instance, argument and local. Modern Age Coders teaches this chapter live in a Tuesday and Wednesday mini batch in India, or one to one at the family's time.

Q1. What are access specifiers in Java?

Access specifiers Java ICSE: private, public, protected and default in one table

An access specifier is a keyword placed before a member that decides which other classes may use it. The ICSE syllabus names three, private, protected and public; a member written with no keyword gets a fourth level, called default or package access.

SpecifierSame classAnother class, same packageSubclass, other packageAny other class, other package
privateYesNoNoNo
none (default)YesYesNoNo
protectedYesYesYesNo
publicYesYesYesYes

Read the table as a ladder: each row opens one more door than the row above it. We did not copy it from a book. We wrote a class Locker in a package school with one member at each level, then tried to read all four from three places. Here is what javac 21 reported.

school/Locker.javaone member per level
package school;
public class Locker {
    private int code = 4821;
    int row = 3;                  // no keyword: default
    protected String owner = "Tara";
    public int number = 17;
}

Each member is then printed from Office (package school), SportsLocker (package other, extends Locker) and Visitor (package other, unrelated).

What javac said6 errors
school/Office.java:5: error: code has private access in Locker
other/SportsLocker.java:5: error: code has private access in Locker
other/SportsLocker.java:6: error: row is not public in Locker; cannot be accessed from outside package
other/Visitor.java:6: error: code has private access in Locker
other/Visitor.java:7: error: row is not public in Locker; cannot be accessed from outside package
other/Visitor.java:8: error: owner has protected access in Locker

Every line that is not listed compiled. public number was readable from all three places; private code from none of them.

Encapsulation, in one line

Binding data and the methods that work on it into a single unit, the class, so that the data is used only in the ways the class allows.

Data hiding, in one line

Keeping data members private so that no code outside the class can read or change them directly.

Access specifier, in one line

A keyword that sets the visibility of a class member: private, protected, public, or none for default access.

Inheritance is not part of the ICSE Class 10 syllabus, so for the 2027 paper it is enough to know that protected opens a member to subclasses as well as to its own package. Where a class sits among objects and classes generally is covered on class as the basis of all computation.

Q2. How does a class hide its data?

Data hiding ICSE: private members with getter and setter methods

A class hides its data by declaring the members private and offering public methods to read them (accessors, or getters) and to change them (mutators, or setters). The mutator can check a value before accepting it, which is the whole point.

Thermostat.java and Room.javarun in Java 21
class Thermostat {
    private double temp = 24.0;

    public double getTemp() {       // accessor
        return temp;
    }

    public void setTemp(double t) { // mutator
        if (t >= 16 && t <= 30)
            temp = t;
        else
            System.out.println("Rejected: " + t);
    }
}

class Room {
    public static void main(String[] args) {
        Thermostat ac = new Thermostat();
        ac.setTemp(45);
        ac.setTemp(19.5);
        System.out.println(ac.getTemp());
    }
}

// Output:
Rejected: 45.0
19.5

45 is an int argument, widened to the double 45.0, which is why the message prints 45.0.

Trying to skip the setterjavac 21
class Hack {
    public static void main(String[] args) {
        Thermostat ac = new Thermostat();
        ac.temp = 45;                // line 4
        System.out.println(ac.getTemp());
    }
}

// javac says:
Hack.java:4: error: temp has private access in Thermostat
        ac.temp = 45;
          ^

The program never runs. Because temp is private, the only way to change it is setTemp, and setTemp refuses 45. That refusal is data hiding doing its job.

Encapsulation, data hiding and abstraction: the difference

TermWhat it meansIn the Thermostat class
EncapsulationData and methods bundled in one classtemp, getTemp and setTemp live together in Thermostat
Data hidingData kept out of reach of other classestemp is private, so Room cannot touch it
AbstractionShowing what an object does, not howRoom calls setTemp without knowing the 16 to 30 rule inside it
  1. Data members are usually private; methods that other classes need are public.
  2. A getter returns the member's type and takes no parameter: double getTemp().
  3. A setter is usually void and takes one parameter of the member's type.
  4. A private method is allowed: it is a helper used only inside its own class.
  5. A private member is still fully usable inside its own class, including in main if main belongs to that class.

The last rule surprises students in output questions: a main written inside the same class can read a private member directly. Constructors that fill private members are on ICSE Class 10 constructors questions.

Q3. What is the scope of a variable?

Scope of variables ICSE: class, instance, argument and local variables

The scope of a variable is the part of the program in which it can be used, and its lifetime is how long it keeps its value. The syllabus names four kinds, and each is decided purely by where the variable is declared.

KindDeclaredUsable inLivesDefault value?
Class variableIn the class, with staticThe whole class; outside it as ClassName.var if access allowsAs long as the program runs; one copyYes (0, 0.0, false, null)
Instance variableIn the class, without staticAll non-static methods; through an object elsewhereAs long as its object; one copy per objectYes
Argument variableIn a method or constructor headerThat method body onlyOne call of the methodNo, it receives the passed value
Local variableInside a method or a block { }From its declaration to the end of that blockUntil the block endsNo, must be assigned before use
Ticket.javaall four kinds
class Ticket {
    static int sold = 0;   // class variable
    int seat;              // instance variable

    Ticket(int s) {        // s: argument variable
        seat = s;
        sold++;
    }

    int price(int rows) {  // rows: argument variable
        int base = 150;    // local variable
        return base + rows * 20;
    }

    public static void main(String[] args) {
        Ticket a = new Ticket(12);
        Ticket b = new Ticket(30);
        System.out.println(a.seat + " " + b.seat + " " + Ticket.sold);
        System.out.println(a.price(3));
    }
}

// Output:
12 30 2
210

Two objects, so two seats but one sold counter. base and rows vanish when price returns.

Shadow.javaa parameter hides a member
class Shadow {
    int marks = 40;

    void update(int marks) {
        marks = marks + 5;
        System.out.println(marks + " " + this.marks);
    }

    void fix(int marks) {
        this.marks = marks;
    }

    public static void main(String[] args) {
        Shadow s = new Shadow();
        s.update(70);
        s.fix(62);
        System.out.println(s.marks);
    }
}

// Output:
75 40
62

Inside update, plain marks means the parameter, so the member stays 40. this.marks always means the member, which is how fix reaches it.

Scope of variables ICSE: five output questions

All five use one class Q with static int count = 10;, int n = 1;, static void bump(int count) { count += 5; } and void twice() { int n = 7; n *= 2; this.n += n; }.

#Code in mainOutputThe scope rule
1bump(count);
System.out.println(count);
10The parameter count is a separate local copy; the class variable is untouched
2Q x = new Q();
x.twice();
System.out.println(x.n);
15The local n becomes 14; this.n is the member, 1 + 14
3Q p = new Q(), r = new Q();
p.count++; r.count++;
System.out.println(Q.count + " " + p.n);
12 1Both objects share the one static count; each has its own n
4int total = 0;
for (int i = 1; i <= 4; i++) { int sq = i * i; total += sq; }
System.out.println(total);
30sq is created afresh each pass; total lives outside the loop and keeps adding
5int k = 3;
{ int m = k * 2; k = m + 1; }
System.out.println(k);
7m dies at the closing brace, but the change it made to k survives
Out of scopejavac 21
int sum = 0;
for (int i = 1; i <= 5; i++)
    sum += i;
System.out.println(sum + " " + i);   // line 6

// javac says:
Loop.java:6: error: cannot find symbol
  symbol:   variable i

i was declared in the for header, so it ends with the loop. Declare it before the loop if it is needed afterwards.

Declared twicejavac 21
void show(int x) {
    int x = 5;                       // line 3
    System.out.println(x);
}

// javac says:
Dup.java:3: error: variable x is already defined in method show(int)

A local variable may hide a data member, but it may not reuse the name of a parameter or another local in the same method.

More traces of this kind, mixed with every other trap, sit among the ICSE Java output questions.

Q4. How does encapsulation look in a Section B answer?

A Section B class with private data members, solved and run

Section B questions rarely say "encapsulation", but a full-marks class answer uses it: private data members, a constructor, public methods that check values before changing them, and a variable description table. Here is an original question in board shape.

Question. Define a class MetroCard with private data members holder (String), cardNo (long) and balance (double). Write a parameterised constructor that stores the name and card number and sets the balance to 0. Write public methods: String getHolder() and double getBalance(); void recharge(double amt) which refuses amounts below 100 and adds a bonus of 5% when the amount is 1000 or more; boolean travel(int stations) which charges a fare of 10 for the first station and 4 for every further station, with a ceiling of 60, deducting it only if the balance is enough; and void display(). In main, read the name, card number, a recharge amount and the stations for two trips, and display the card.

MetroCard.javaprivate data, public methods
import java.util.Scanner;
class MetroCard {
    private String holder;    // name on the card
    private long cardNo;      // card number
    private double balance;   // money left on the card

    public MetroCard(String h, long c) {
        holder = h;
        cardNo = c;
        balance = 0.0;
    }

    public String getHolder() {
        return holder;
    }

    public double getBalance() {
        return balance;
    }

    public void recharge(double amt) {
        if (amt < 100) {
            System.out.println("Minimum recharge is 100");
            return;
        }
        double bonus = (amt >= 1000) ? amt * 0.05 : 0;
        balance = balance + amt + bonus;
    }

    public boolean travel(int stations) {
        int fare = 10 + 4 * (stations - 1);
        if (fare > 60)
            fare = 60;
        if (fare > balance) {
            System.out.println("Low balance, fare " + fare);
            return false;
        }
        balance = balance - fare;
        return true;
    }

    public void display() {
        System.out.println("Card " + cardNo + " (" + holder + ")");
        System.out.println("Balance: " + balance);
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Name and card number: ");
        String n = sc.next();
        long c = sc.nextLong();
        MetroCard card = new MetroCard(n, c);
        System.out.print("Recharge amount: ");
        card.recharge(sc.nextDouble());
        System.out.print("Stations on each of two trips: ");
        int t1 = sc.nextInt();
        int t2 = sc.nextInt();
        card.travel(t1);
        card.travel(t2);
        card.display();
    }
}

No method lets the balance be set to any value directly. Money comes in only through recharge and goes out only through travel, and both check first.

VariableTypeScopePurpose
holderStringinstance, privatecard holder's name
cardNolonginstance, privatecard number
balancedoubleinstance, privatemoney on the card
h, cString, longargumentvalues passed to the constructor
amtdoubleargumentamount offered for recharge
bonusdoublelocal5% extra on large recharges
stationsintargumentstations travelled on a trip
fareintlocalfare for one trip, at most 60
sc, n, c, t1, t2, cardvariouslocal to maininput reader, inputs and the object
Sample runsJava 21
Name and card number: Kabir 40071
Recharge amount: 1000
Stations on each of two trips: 6 18
Card 40071 (Kabir)
Balance: 960.0

Name and card number: Mira 40072
Recharge amount: 50
Minimum recharge is 100
Stations on each of two trips: 2 3
Low balance, fare 14
Low balance, fare 18
Card 40072 (Mira)
Balance: 0.0

Run 1: 1000 plus a bonus of 50 is 1050. Six stations cost 10 + 4 × 5 = 30; eighteen would cost 78, so the ceiling of 60 applies. 1050 − 30 − 60 = 960.

Adding a Scope column to the variable description table, as above, is not required, but it shows the examiner you know the chapter. More classes written to a specification are on ICSE slab and bill programs and user-defined methods and overloading.

Q5. What does Section A ask on this chapter?

Encapsulation ICSE Class 10 questions with answers

In Section A, the 40 compulsory marks, this chapter turns up as one-mark MCQs and two-mark definitions or differences. Try each one before opening the answer.

One-mark questions

  1. Which access specifier makes a member visible only inside its own class? (a) public (b) protected (c) private (d) default
    Answer (c) private.
  2. A member declared with no access specifier can be used by:
    Answer Any class in the same package, but no class outside it.
  3. Which keyword lets a method reach a data member hidden by a parameter of the same name?
    Answer this, as in this.marks = marks;
  4. Name the kind of variable declared inside a method body.
    Answer A local variable.
  5. Which kind of variable has exactly one copy however many objects exist?
    Answer A class variable, declared with static.
  6. Which of these is the most open: protected or default?
    Answer protected. It allows everything default allows, plus subclasses in other packages.

Two-mark questions

  1. Define encapsulation. How does a class implement it?
    Answer Encapsulation is wrapping data and the methods that operate on it into a single unit. A class implements it by declaring the data members and methods together, and by keeping the data private and reachable only through its public methods.
  2. Differentiate between private and public members.
    Answer A private member can be used only inside its own class; a public member can be used by any class in any package. Data members are usually private and the methods others need are public.
  3. State the difference between an instance variable and a local variable.
    Answer An instance variable is declared in the class outside every method, belongs to an object and gets a default value. A local variable is declared inside a method or block, exists only until that block ends and must be assigned before use.
  4. Why is data hiding useful? Give one example.
    Answer It stops other classes from putting an object into an impossible state. A private balance can be changed only through a method that refuses a negative amount, so the balance is always valid.
  5. What is the scope of an argument variable?
    Answer The body of the method or constructor in whose header it is declared. It is created when the method is called, holds the passed value, and ends when the method returns.

Short difference questions from every chapter, in the same two-mark shape, are collected on ICSE Computer Applications difference between questions.

Q6. How is this chapter taught in the mini batch?

Learning access and scope by breaking code on purpose

Students remember the access table best after they have watched the compiler refuse a line they were sure would work. So the week is built around predictions that javac then confirms or rejects.

  1. Predict, then compile

    At the Tuesday 5:30 PM IST class the teacher shows a two-package project on a shared screen. Each student marks which lines will compile before BlueJ is asked, and the wrong guesses are discussed first.

  2. Scope traced in a table

    Fragments with shadowed names, static counters and block-local variables are traced on paper, one column per variable, until the four kinds of variable feel different rather than merely sound different.

  3. A class written by hand

    On Wednesday at 8:00 PM IST the group writes a Section B class with private members and checking methods, then marks it against the board scheme on screen, including the variable description table.

  4. Definitions said aloud

    The one-line definitions of encapsulation, data hiding and each specifier are rehearsed until each student can say them without notes, which also prepares for the internal assessment viva.

  5. Back in every mock

    From December, full two-hour mock papers bring the chapter back inside Section A and inside Section B classes, under the real clock.

The wider chapter-by-chapter plan is on ICSE Computer Applications notes, and the oral side is on ICSE Computer Applications viva questions.

Batch or personalised: you choose

Learn encapsulation in the mini batch, or one to one

The access experiments, the scope traces and the Section B class are the same in either format. Families in India choose between the fixed evening group of six and a private slot; ICSE students abroad are taught one to one. Billing is monthly and there is no admission fee.

Option 1 · Fixed batch timings

Mini batch, Tuesday 5:30 PM and Wednesday 8 PM

₹2,999

per month, two live classes a week

  • Tuesday 5:30 PM and Wednesday 8:00 PM IST, live
  • Six ICSE Class 10 students at most
  • Predict-then-compile access drills on a shared screen
  • A class with private data written and marked each week
  • Definitions rehearsed aloud for the viva
Book a free demo in this batch

Option 2 · Choose your own timing

Personalised one to one

₹4,999

per month, one private class a week, at a time set with you

  • A slot the family picks, in India or overseas
  • Extra time on whichever of access or scope is shaky
  • Your child's own school classes refactored to private data
  • Harder shadowing traces once the basics are steady
  • Same teachers and the same 2027 syllabus
Ask for a personalised plan

A student who already writes working classes but loses marks on definitions or scope traces usually needs only a handful of one to one sessions on this chapter. A student who is still unsure how a class should be laid out gains more from the steady weekly rhythm of the batch. Fees appear in your own currency.

Studying outside India?

Encapsulation lessons for ICSE students abroad

The 2027 Computer Applications paper is the same in Dubai or Singapore as it is in Kolkata, and so is this chapter. Outside India we teach it one to one, at an early evening hour in the student's own time zone.

Where you liveTime differenceUsual class window, local timeFormat
India (IST)
every Indian city
ISTTue 5:30 PM, Wed 8:00 PMMini batch or 1-on-1
United Arab Emirates
Dubai, Sharjah
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Indonesia and Thailand
West Java, Bangkok area
1 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1
Singapore
Singapore
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1

The time is fixed after the free demo and can move around school tests. How classes run for overseas families is set out on ICSE Computer Applications classes in the Gulf and abroad.

What families say

Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 10 series

More pages for Class 10 board students

Every page in the ICSE Class 10 Computer Applications series, grouped by what you need: classes, each chapter, Section B programs, question practice, notes and revision, and the exam itself.

CBSE Class 10 AI (417): The Mon and Wed 9 PM AI batch CBSE AI 417 syllabus explained CBSE AI important questions Sample paper and mock tests

Questions about encapsulation

What students ask about encapsulation and access specifiers

What is encapsulation in Java ICSE Class 10?

Encapsulation is the wrapping of data and the methods that act on that data into a single unit called a class. In practice it means keeping the data members private and letting other classes use them only through the class's public methods, so the class decides what changes are allowed. It is Unit 6 of the 2026-27 ICSE Computer Applications syllabus.

What are the access specifiers in Java for ICSE?

The syllabus names private, protected and public. private allows access from the same class only; protected from the same package and from subclasses; public from everywhere. A member with no specifier has default, or package, access: any class in the same package can use it, but nothing outside the package can.

What is the difference between private, public and protected?

They differ in how far a member can be seen. private stops at the class itself. protected reaches the whole package and any subclass, even one in another package. public reaches every class in every package. Data members are usually private and methods that other classes call are public.

What is data hiding in ICSE Computer Applications?

Data hiding means keeping a class's data members private so that code outside the class cannot read or change them directly. Other classes must go through public methods, which can check every value first. For example, a private balance changed only by a method that refuses negative amounts can never become negative.

What is the difference between encapsulation and data hiding?

Encapsulation is the bundling of data and methods into one class. Data hiding is one result of it: restricting direct access to that data with the private specifier. A class could bundle data and methods yet leave everything public; that is encapsulated but not hidden, and it is weak design.

What is the scope of variables in Java ICSE?

Scope is the region of a program where a variable can be used. Class variables (static) and instance variables can be used throughout the class. An argument variable can be used only inside its own method. A local variable can be used only from its declaration to the end of the block in which it is declared.

What are the four types of variables in ICSE Class 10?

Class variables, declared static with one shared copy; instance variables, declared in the class without static, one copy per object; argument variables, declared in a method header to receive values; and local variables, declared inside a method or block. The syllabus groups all four under the scope of variables in the Encapsulation unit.

Can a private variable be accessed outside the class?

Not directly. The compiler rejects the line with a message such as "temp has private access in Thermostat". The only way in is through a non-private method of the same class, such as a getter that returns the value or a setter that checks and stores a new one.

Is protected access asked in ICSE Class 10 even though inheritance is not in the syllabus?

The syllabus lists protected among the access specifiers, so a one-mark question on its visibility is fair. You need the rule, not inheritance programs: protected allows access within the same package and from subclasses in other packages. Writing subclasses is an ISC topic.

Do you teach encapsulation and access specifiers in live classes?

Yes. The ICSE mini batch meets on Tuesday at 5:30 PM IST and Wednesday at 8:00 PM IST with six students at most. Students predict which lines compile, trace scope fragments and write a class with private data each week. Personalised one to one classes are available at a time the family chooses, in India or abroad.

Start

Try a free live class on encapsulation

In the free demo your child predicts which lines of a small two-package program will compile, sees BlueJ confirm or reject each guess, and then rewrites one class so its data is private. You then hear honestly which parts of the chapter are secure and whether the mini batch or one to one fits better.

Prefer to look around first? Read ICSE Computer Applications important questions or see the ICSE Class 10 Java classes.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Every class is live video. The form requests a callback and reserves nothing.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

Book a priority demo

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here