Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

ELEMENTARY

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;

Computer Applications-Lorven public school, Chanadapura


Computer applications - Lorven public school, Chandapura
 Package p1
 c1- c2
 C3
 C4
Package p2
(C1) -C5
C6
C7 -c8

Computer Applications-Lorven public school, Chandapura


CLASSES Continued..

 Now lets see what does a body of class contain,


 It contains data members and member functions.
 We know that object is a real world entity. It has its own behaviour and
characteristics.
 In software class objects behaviour and characteristics are taken as its data
members and member functions.
 If car is a class, its colour, model, type of car can be its characteristics and
accelerate() and decelerate() can be its function.
 https://www.programiz.com/java-programming/class-objects

Computer Applications-Lorven public school, Chanadapura


CREATING AN OBJECT
 Object declaration
 Syntax: Class-name object name;

 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/

Computer Applications-Lorven public school, Chandapura


EXAMPLE
 Class Rectangle
{
//data members
float length, breadth;

//member functions
void input();
void calculate();
void display();
}

Computer Applications-Lorven public school, Chandapura


CREATING OBJECTS
 Rectangle robj1= new Rectangle();
 Rectangle robj2=new rectangle();

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;

Computer Applications-Lorven public school, Chanadapura


MEANINGFUL TERMS TO
REMEMBER
 Class is an object factory.
 Object is an instance of class.
 Class is a user defined data type

Computer Applications-Lorven public school, Chanadapura


IMPORTANT POINTS TO
REMEMBER
 Class creates many objects and interacts by invoking objects.
 Objects always define the following;
 State:
 Its an attribute
 reflects property of an object.
 Behaviour:
 It’s a method
 Reflects the relation of an object with other object.
 Identity:
 It gives an unique identity
 Enables object to interact with other objects.

Computer Applications-Lorven public school, Chandapura

You might also like