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

Lesson 2

Iteration Statements 1

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lesson 2

Iteration Statements 1

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Lesson 2

Elementary concepts of objects and classes


Class
Class is like a blueprint for creating objects .
A class is like a recipe that tells the computer how to make an object. of it
like a recipe that tells you how to make something
Class is also called object factory.(since the class is used to make similar
kind of objects)
It defines what attributes and methods an object should have.
A class defines the attributes(data members) and methods(actions or
functions)that the created object will have.
Method
• A method or function defined inside a class that describes the
behavior or actions that the objects created from the class can
perform.
objects
• Think of objects like things in real life. Just like your phone or your
backpack, objects in programming are containers that hold
information and can do tasks. They have 'attributes' which are like
details (color, size) and 'methods' which are like actions (ringing,
opening).
Instance/ object

Each object of a class possesses the characteristics and the behavior


described within the class.

• Data members are called characteristics /attributes


• Behaviour is called methods/functions.

An object is also called an instance of a class.


Creating an object of a class
Syntax

<class name><object name>=new <class name>();

new keyword- is used to allocate space in the dynamic memory for the
storage of data and functions belonging to an object
Instance means member
What is instantiation?
The process by which a class blueprint is used to create a specific object
with its own distinct set of attributes and behaviors
// Define the class
public class Student
{
// Attributes /data members/characteristics(properties)
int age;
int rollno;
string name;
//methods
Attend class();
Write exam();
• Class car
//attributes/data members are
Make;
Model;
Color;
//method
Start
Accelerate
Stop
For different car data members will be different but method will be same.
• Object is the real thing you create using the blueprint. It follows the
description and instructions from the class.
Objects classified into two
Real world objects
Software objects
Real world objects are physical objects that exists in the world around us.
You can touch ,have a physical presence , see,or interact with them directly.
It exists independently of computers or software
Eg: car
Whereas software objects are the virtual versions of real world objects
created inside a computer program .
they don’t have physical presence they exist inside the computers memory
Or it represent things or ideas that the program needs to work with.
Eg mycar1,mycar2
Message passing
• It is the mechanism through which objects invoke methods on each
other to request action or retrieve information.
• Think of objects in a program like characters in a story
• They talk to each other by calling each others names(objects)and
asking for things or telling each other what to do

• This is also called calling a method or invoking a method


• Object collaborate through methods or functions to achieve task.
• Class is an object factory
• Factory create similar kinds of objects
• Objects have different characteristics and common behavior
• The process of creating objects are called instantiation
• Class is a user defined data types
• In java we have some pre defined data types like int,float,char etc
The users can create their own data types
The class itself is a user defined data type
In class you can define the characteristics and behavior this is the
reason why a class is defined to as user defined data type.
• Object is an instance of a class
• Each object is created from a class and so is called an instance of a
class
• Difference between object and class.
• class
• It is a representation of an abstraction only
• It is an object producer and called a blue print for a set of objects
• Known as object factory
• Object
• it is a real and unique entity having some characteristics and behaviour
• It is created with the help of the new operator
• It is known as an instance of a class.

You might also like