Page 351 - CA_Blue( J )_Class10
P. 351
16 count_object ob=new count_object();
17 ob.increase();
18 System.out.print("Do you want more : ");
19 n=sc.next().charAt(0);
20 if(n=='N' || n=='n')
21 break;
22 }
23 }
24 }
You will get the following output:
Object Number : 1
Do you want more : y
Object Number : 2
Do you want more : y
Object Number : 3
Do you want more : y
Object Number : 4
Do you want more : n
14.3.3 Instance Variables
They are also known as non-static data members. They are created whenever any object is generated. Every instance
variable is accessed by preceding it with the object name. They are declared in a class, but outside a method, i.e., both
constructor and user-defined method. A distinct copy of the variables is be created for each object of the class.
Program 6 To print the sum of the digits in a number.
1 import java.util.*;
2 class instance_variable
3 {
4 int n,t,s;
5 void input()
6 {
7 Scanner sc= new Scanner(System.in);
8 System.out.println("Enter a number : ");
9 n=sc.nextInt();
10 t=n;
11 }
12 void display()
349
Encapsulation and Inheritance 349

