Professional Documents
Culture Documents
12 Class
12 Class
class Class_Name
{
DataType instance_variable;
DataType method_name(parameter_list)
{
// body of method
}
}
Declaring Objects
Obtaining objects of a class is a two-step process.
• First, must declare a variable of the class type
• Second, must acquire an actual, physical copy of the object
and assign it to that variable
General form of Objects
Class_Name Object_Name ;
Object_Name = new Class_Name( );
The dot operator links the name of the object with the
name of an instance variable
Difference b/w Class and Objects
Assigning Object Reference Variables
Box b1 = new Box();
Box b2 = b1;
General form of a method
DataType Method_Name(parameter_list)
{
// body of method
return Value;
}
Constructors
Automatic initialization all of the variables in a class each time
an instance is created.
It has the same name as the class in which it resides.
The constructor is automatically called immediately after the
object is created, before the new operator completes.
Implicit return type of a class constructor is the class type itself