8 ClassAndObject
8 ClassAndObject
Java
2. In the class we can declare a variable called fields , which are used to store the data
3. We can also define functions called methods, which are used to manipulate the values
Object:
> As we know that class is a logical representation, it doesn’t occupy any space to store
the data, To store the data and to access members of the class then we required to create
a physical representation of the class called an “Object”
1|Page
SSSIT Computer Education
Besides R.S Brothers Show Room
Kphb – Hyderabad : 9866144861
Java
2|Page
SSSIT Computer Education
Besides R.S Brothers Show Room
Kphb – Hyderabad : 9866144861
Java
Image :
Ex1:
class Sample
{
}
class ObjectDemo
{
public static void main(String args[])
{
Sample s; // s is reference variable
s=new Sample( );
System.out.println(s);
}
}
Eg:
3|Page
SSSIT Computer Education
Besides R.S Brothers Show Room
Kphb – Hyderabad : 9866144861
Java
class Test
{
int x;
}
class ObjectDemo2
{
public static void main(String args[ ])
{
Test t=new Test( );
t.x=10;
// System.out.println(x);
System.out.println("x val is : "+t.x);
}
}
//Testing.java
class Testing
{
int x;
4|Page