Saturday, 5 September 2015

Rules of oops

Rules of oops.

First rule=>

To access member of class from outside of class we have to create object of same class .

General syntax to create object of class.

class name object name=new class name();
class1 obj 1 = new class1();

class name object name();

Example=>

class1 customer 1;
customer cusID=new customer;

class class1
private int a,b;
public int c;
public void set data1()
{
a=5;b=7;c=9;
}
public void set data2 (int x,int y,int z)
{
a=x;
b=y;
c=z;
}
public void set data3(int a,int b,int c);
{
a=a;
b=b;
c=c;
}
second rule=>


Every object have three separate memory blocks.

class1 ob 1=new class1();
obj1.a=25;

class1 ob 2= new class1();
ob 2.b=5;
ob 2.set data z(10,20,30);

class1 ob 3=new class1();
ob 3.set data 3(100,200,300);


No comments:

Post a Comment