0% found this document useful (0 votes)
573 views

Elementary Concepts of Objects and Classes: Computer Applications-Lorven Public School, Chandapura

This document discusses classes and objects in object-oriented programming. A class defines common properties and behaviors of objects, and acts as a blueprint to create many objects. Objects are instances of a class and have their own unique properties but share the same behaviors defined in the class. The document provides an example Animal class with objects like dog, cat, and cow as instances. It also demonstrates how to declare classes with data members and member functions, and how to define and initialize objects from classes using the new operator.

Uploaded by

ks.ashwini
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
573 views

Elementary Concepts of Objects and Classes: Computer Applications-Lorven Public School, Chandapura

This document discusses classes and objects in object-oriented programming. A class defines common properties and behaviors of objects, and acts as a blueprint to create many objects. Objects are instances of a class and have their own unique properties but share the same behaviors defined in the class. The document provides an example Animal class with objects like dog, cat, and cow as instances. It also demonstrates how to declare classes with data members and member functions, and how to define and initialize objects from classes using the new operator.

Uploaded by

ks.ashwini
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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