Static Members, this Keyword, Number Programs and Roots of Equations (ISC Class 11)
Updated 17 October 2026 · Fact-checked
A static variable belongs to the class and is shared by all objects; a static method can be called without an object and can use only static members directly. The this keyword refers to the current object and separates instance variables from parameters of the same name. Standard number programs use loops with % and /: GCD by Euclid, perfect, Armstrong and palindromic numbers; roots of equations are found by the quadratic formula or by repeated halving (bisection).
The static variable n exists once in the class and every object shares it, while each object keeps its own id.
Illustration drawn for QuestionBuddy.
Understand Static Members, the this Keyword, Number Programs and Finding Roots of Equations
Static members.
class C {
static int n = 0; // one copy for the whole class
int id; // one copy per object
C() { n++; id = n; }
static int count() { return n; }
}After three objects C.n is 3 and the last object's id is 3. A static method is called as C.count(); it cannot use this or instance variables directly.
this keyword. this refers to the object on which the method or constructor is running.
Box(int l, int b) { this.l = l; this.b = b; } // l on the left is the fieldNumber programs (loop with % and /).
- *Reverse:* r = r * 10 + n % 10; n = n / 10. 1234 gives 4321. A number is a palindrome if it equals its reverse (121).
- *GCD (Euclid):* while (b != 0) { t = a % b; a = b; b = t; } a is the GCD. gcd(48, 18) = 6.
- *Perfect number:* equals the sum of its proper divisors (28 = 1 + 2 + 4 + 7 + 14).
- *Armstrong number:* equals the sum of the cubes of its digits (153 = 1 + 125 + 27).
- *Prime:* no divisor from 2 to the square root of n.
Roots of an equation. *Quadratic ax^2 + bx + c = 0:* D = b^2 - 4ac; roots (-b +/- sqrt(D)) / (2a) if D >= 0; none real if D < 0. *Bisection:* if f(a) and f(b) have opposite signs, the root lies between them; take mid = (a + b)/2 and keep the half where the sign changes; repeat until the interval is small.
Static Members, the this Keyword, Number Programs and Finding Roots of Equations: key facts
- Quadratic roots
- D = b^2 - 4ac | x = (-b + sqrt(D)) / (2a) and (-b - sqrt(D)) / (2a)
- Real roots if D >= 0.
- Euclid GCD
- gcd(a, b) = gcd(b, a % b) | Stop when b = 0
- Repeat.
- Digit loop
- digit = n % 10
- n = n / 10
- r = r x 10 + digit
- Reverse a number.
How to answer Static Members, the this Keyword, Number Programs and Finding Roots of Equations questions
Trace the loop with a table of the variables.
- 1Write the starting values.
- 2For each iteration compute the digit or remainder and update the variables.
- 3Stop when the loop condition fails.
- 4State the output exactly.
Static Members, the this Keyword, Number Programs and Finding Roots of Equations in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Static counter
Suppose a school software counts how many Student objects have been created, so that each new student gets the next roll number.
Why is the counter static?
Try it first, then show the solutionSolution
- The counter must be shared by all objects.
- A static variable has one copy for the class, so every constructor call increments the same count.
Answer: A static variable is shared by all objects.
Memory hook: Static means one for the class.
Tricks to remember Static Members, the this Keyword, Number Programs and Finding Roots of Equations
Short memory aids. Say each one aloud once, then use it on a question the same day.
Static = shared
One copy for the whole class.
Use it when: Static.
this.x = x
Left x is the field, right x the parameter.
Use it when: this.
mod and divide by ten
% 10 takes the digit; / 10 drops it.
Use it when: Digit programs.
Static Members, the this Keyword, Number Programs and Finding Roots of Equations: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Static · 1 mark · MCQBoard level
A variable declared static in a class:
(a) is created separately for each object (b) is shared by all objects of the class (c) cannot be changed (d) can be used only inside constructors
Try it first, then show the solutionSolution
- There is one copy per class.
Answer: (b) is shared by all objects of the class
Example 2: Static counter output · 3 marks · Short answerBoard level
With the class C of the concept (n static, id instance), give the output: C a = new C(); C b = new C(); C c = new C(); System.out.println(a.id + " " + b.id + " " + c.id + " " + C.count()); (3 marks)
Try it first, then show the solutionSolution
- a: n = 1, id = 1; b: n = 2, id = 2; c: n = 3, id = 3.
- C.count() returns 3.
Answer: 1 2 3 3
Example 3: Number programs · 6 marks · Long answerHarder board level
Trace and state the output: (a) reverse of 1234; (b) gcd(48, 18); (c) whether 28 is a perfect number; (d) whether 153 is an Armstrong number. Write the reverse loop. (6 marks)
Try it first, then show the solutionSolution
- (a) n = 1234, r = 0: r = 4, n = 123; r = 43, n = 12; r = 432, n = 1; r = 4321, n = 0: 4321.
- (b) (48, 18) to (18, 12) to (12, 6) to (6, 0): gcd 6.
- (c) divisors 1, 2, 4, 7, 14 sum to 28: perfect.
- (d) 1 + 125 + 27 = 153: Armstrong.
Answer:
(a) 4321; (b) 6; (c) yes; (d) yes.int r = 0;
while (n > 0) {
r = r * 10 + n % 10;
n = n / 10;
}
Example 4: Roots of equations · 7 marks · Long answerHarder board level
Find the roots of x^2 - 5x + 6 = 0 with the formula. Then use bisection on f(x) = x^2 - 2 in [1, 2] for four steps, giving the interval after each and an approximate root. (7 marks)
Try it first, then show the solutionSolution
- D = 25 - 24 = 1; roots (5 + 1)/2 = 3 and (5 - 1)/2 = 2.
- Bisection: f(1) = -1 and f(2) = 2.
- mid 1.5: f = 0.25 > 0, interval [1, 1.5]. mid 1.25: f = -0.4375 < 0, interval [1.25, 1.5].
- mid 1.375: f = -0.109375 < 0, interval [1.375, 1.5]. mid 1.4375: f = 0.0664 > 0, interval [1.375, 1.4375].
- Approximate root = (1.375 + 1.4375)/2 = 1.40625 (the true value is about 1.4142).
Answer: Roots 3 and 2. After four steps the root lies in [1.375, 1.4375]; the estimate is about 1.406.
Example 5: this and shadowing · 4 marks · Short answerHOTS / competency
What is the output? class P { int x; P(int x) { x = x; } } and System.out.println(new P(5).x); Explain the output and correct the constructor. (4 marks)
Try it first, then show the solutionSolution
- Inside the constructor the parameter x hides the field x.
- x = x assigns the parameter to itself; the field keeps its default 0.
- Output: 0. Correction: this.x = x;
Answer: Output 0; correct with this.x = x; so that the field gets 5.
Where students lose marks in Static Members, the this Keyword, Number Programs and Finding Roots of Equations
The slips examiners see most often, and what to write instead.
Mistake: Forgetting to update n in the digit loop
Infinite loop.
Wrong working
No n = n / 10
Right working
Update n
Do this: Check the loop variable.
Usually costs: 2 marks.
Mistake: Using instance variables in a static method
No object.
Wrong working
static method uses id
Right working
Use an object or static data
Do this: Static methods cannot use this.
Usually costs: 1-2 marks.
Mistake: Not using this when names clash
Shadowing.
Wrong working
x = x
Right working
this.x = x
Do this: Qualify the field.
Usually costs: 2 marks.
Exam tips
- Make a trace table for digit loops.
- State how many times the loop runs.
- Write this. whenever the parameter and field names are the same.
Practice questions on Static Members, the this Keyword, Number Programs and Finding Roots of Equations
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
The keyword that refers to the current object is:
(a) super (b) this (c) static (d) finalHint
Current object.
Answer
(b) this
Q2 · 4 marks · Short answerBoard level
Write a method that returns true if an integer n is a palindrome, and give the result for 121 and 123. (4 marks)
Hint
Reverse and compare.
Answer
Reverse n into r with the digit loop and return r == original. 121 gives true; 123 reverses to 321 and gives false.
Q3 · 5 marks · Long answerHarder board level
Trace gcd(84, 36) by Euclid's method and state the LCM using LCM = a x b / gcd. Also find the sum of the digits of 9,075 with a loop. (5 marks)
Hint
84 % 36 = 12.
Answer
(84, 36) to (36, 12) to (12, 0): gcd 12. LCM = 84 x 36 / 12 = 252. Digit sum of 9075 = 5 + 7 + 0 + 9 = 21.
Q4 · 4 marks · Short answerHarder board level
Find the roots of 2x^2 - 7x + 3 = 0 and the nature of roots of x^2 + 2x + 5 = 0. Write the Java condition that tests the discriminant. (4 marks)
Hint
D = 49 - 24.
Answer
D = 49 - 24 = 25: roots (7 + 5)/4 = 3 and (7 - 5)/4 = 0.5. For x^2 + 2x + 5: D = 4 - 20 = -16 < 0: no real roots. Condition: if (d >= 0) { ... } else { ... }.
Q5 · 3 marks · Short answerHOTS / competency
A class counts its objects with a static variable, but a student declares the count without static and prints it from each of three objects. Predict the output, explain and fix. (3 marks)
Hint
Each object has its own copy.
Answer
Each object has its own count that starts at 0 and is incremented to 1 in its own constructor, so each prints 1. Declare the counter static so that all objects share one copy; then the prints show 3 after three objects are created.
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.Static variable copies?Show answer
One for the class.
2.this means?Show answer
The current object.
3.Euclid stops when?Show answer
The divisor is zero.
4.D less than 0 means?Show answer
No real roots.
5.Reverse step?Show answer
r = r * 10 + n % 10.
Static Members, the this Keyword, Number Programs and Finding Roots of Equations: frequently asked questions
Can a static method call an instance method?
Only through an object.
Is main static?
Yes.
What is an Armstrong number?
Sum of cubes of digits equals the number (for 3 digits).
What does bisection need?
Opposite signs of f at the ends.