Classes and Object

Main concept of object oriented language


           Classes are the basis for any object oriented system classes have well defined boundaries and describe a set of objects that share similar properties and perform similar functions. Classes can be reused within a system or they can be used while developing a new system.


             Objects are also the main concept of object oriented language.The example of real world example are table,TV,person(male or female).Every object have state and behavior like person have state(name,color) and behavior like(walking,talking).Same in a programming variables are the fields of object and methods are the behavior of the object.Object is the instance of the class.

………… Example of class and object is……….

   class rectangle   //name of the class is rectangle


int l,b;         // integer variable l and b

public void getdata( int x, int y)   //function with arguments x and y(formal argument)


l=x;   //value passes from x to l

b=y; //value given to b


int rectarea()     //function without argument


int area=l*b;   //calculation to find the area of rectangle

return(area);   //return is used because of int function rectarea()


class rect   //main class


public static void main(String aa[])


int area; //integer variable area is used to call the function rectarea because the function is return type

rectangle r11=new rectangle();         //r1 is the object of class rectangle

r11. getdata (2,12);               /*calling function getdata and value give to formal argument this is the              

                                                   actual arguments*/

area=r11.rectarea();                                  //calling function rectarea the output is given to variable area

System. out. println ("area="+area);            //print output


Save as……

Run ……..javac

       ………java rect

Output…….area=24(l*b (l=2,b=12))