SSSIT Computer Education: Besides R.S Brothers Show Room KPHB - Hyderabad: 9866144861 Java
SSSIT Computer Education: Besides R.S Brothers Show Room KPHB - Hyderabad: 9866144861 Java
Java
class Demo
{
int y=222; //instance field not static
/*
Note: A variable which is declared in a method, then that variable can be used only
in that method, but a variable which declared as a instance [non static variable] then
it can be
Accessed through out class but we must require an Object reference in static
context */
1|Page
SSSIT Computer Education
Besides R.S Brothers Show Room
Kphb – Hyderabad : 9866144861
Java
Instance Methods:
The methods which are define with in class without static modifier.
Instance methods can perform the operation on both static and non static
variables | fields
2.Immutable Methods
> The methods which doesn’t change the value of the fields or
The methods which are used read the values from the fields called immutable
methods or getter methods or inspectors
class Test
{
int x,y; //instance field non static
void getData()
{ System.out.println("x is : "+x);
System.out.println("y is : "+y); }
2|Page
SSSIT Computer Education
Besides R.S Brothers Show Room
Kphb – Hyderabad : 9866144861
Java
Eg 2:
class Biggest
{
int x,y; //instance field
void findBiggest()
{ if (x>y)
{ System.out.println("biggest is : "+x); }
else
{ System.out.println("biggest is : "+y); }
}
}
}
3|Page
SSSIT Computer Education
Besides R.S Brothers Show Room
Kphb – Hyderabad : 9866144861
Java
Eg 3:
class Student
{
int m1,m2,m3; //instance fields
void getStudent()
{ System.out.println("M1 : "+m1);
System.out.println("M2 : "+m2);
System.out.println("M3 : "+m3); }
}
}
4|Page