Elementary Concepts of Objects and Classes: Computer Applications-Lorven Public School, Chandapura
Elementary Concepts of Objects and Classes: Computer Applications-Lorven Public School, Chandapura
CONCEPTS OF
OBJECTS AND
CLASSES
Computer Applications-Lorven public school, Chandapura
CLASSES
Hence class is prototype for similar type of objects.
Objects are real world entities that have similar behaviour and different properties.
Example Animal class and its objects may be dog, cat, cow etc.
Syntax for creating class and objects is as below.
Access specifier Class class-name
{
Access specifier
// Data members
Access specifier
//Member Functions
} object1, object2,so..on;
Object creation
Syntax: object name= new class-name();
“new” operator is used to allocate memory to the object;
Example: https://www.geeksforgeeks.org/new-operator-java/
//member functions
void input();
void calculate();
void display();
}
robj1 robj2
Length Length
breadth breadth
Input(); Input();
Calculate(); Calculate();
Display() display();
Computer Applications-Lorven public school, Chandapura
EXAMPLE
class car
{
public:
string colour, type, model;
int seats,speed;
void accelerate();
void decelerate();
Void printdetails();
}beat;