SlideShare a Scribd company logo
© Prognoz Technologies Pvt. Ltd
Object & Class
© Prognoz Technologies Pvt. Ltd
What is Object ?
 Objects are key to understanding object-oriented technology.
 Look around right now and you'll find many examples of real-world
objects: your dog, your desk, your television set, your bicycle.
2
© Prognoz Technologies Pvt. Ltd
Continue…
 Real-world objects share two characteristics: They all have state and
behavior.
 Dogs have state (name, color, breed, hungry) and behavior (barking,
fetching, wagging tail).
© Prognoz Technologies Pvt. Ltd
Continue…
Bicycles also have state(current gear, current pedal cadence, current speed)
and behavior (changing gear, changing pedal cadence, applying brakes).
4
© Prognoz Technologies Pvt. Ltd
What is Class ?
 In the real world, you'll often find many individual objects all of the same
kind. There may be thousands of other bicycles in existence, all of the
same make and model.
 Each bicycle was built from the same set of blueprints and therefore
contains the same components.
 In object-oriented terms, we say that your bicycle is an instance of the
class of objects known as bicycles.
 A class is the blueprint from which individual objects are created.
© Prognoz Technologies Pvt. Ltd
Continue…
© Prognoz Technologies Pvt. Ltd
Continue…
OBJECTS
CLASSES
© Prognoz Technologies Pvt. Ltd
A Class acts as the template from which an instance of an object is
created. The class defines the properties of the object and the
methods used to control the object's behavior.
A Class specifies the structure of data as well as the methods which
manipulate that data. Such data and methods are contained in each
instance of the class.
A Class is a model or template that can be instantiated to create
objects with a common definition, and therefore common
properties, operations and behavior.
A Class provides a template for defining the behavior of a particular
type of object. Objects are referred to as “instances” of a class.
© Prognoz Technologies Pvt. Ltd
CLASSES
class One
{
}
class Book
{
}
class College
{
}
class AnyThing
{
}
© Prognoz Technologies Pvt. Ltd
Class Definition
A class contains a name, several variable declarations (instance variables)
and several method declarations. All are called members of the class.
General form of a class:
class classname {
type instance-variable-1;
…
type instance-variable-n;
type method-name-1(parameter-list) {
type method-name-2(parameter-list) {
…
type method-name-m(parameter-list) { …
}
© Prognoz Technologies Pvt. Ltd
Example: Class
A class with three variable members:
class Box {
double width;
double height;
double depth;
}
A new Box object is created and a new value assigned to its width variable:
Box myBox = new Box();
myBox.width = 100;
© Prognoz Technologies Pvt. Ltd
Example: Class Usage
class BoxDemo {
public static void main(String args[]
Box mybox = new Box();
double vol;
mybox.width = 10;
mybox.height = 20;
mybox.depth = 15;
vol = mybox.width * mybox.height * m
System.out.println("Volume is " +
}
}
© Prognoz Technologies Pvt. Ltd
Compilation and Execution
Place the Box class definitions in file Box.java:
class Box { … }
Place the BoxDemo class definitions in file BoxDemo.java:
class BoxDemo {
public static void main(…) { … }
}
Compilation and execution:
> javac BoxDemo.java
> java BoxDemo
© Prognoz Technologies Pvt. Ltd
Variable Independence
Each object has its own copy of the instance variables: changing the
variables of one object has no effect on the variables of another object.
© Prognoz Technologies Pvt. Ltd
OBJECTS
class Book
{
}
class JavaBook
{
public ststic void main(String args[])
{
Book b=new Book();
}
}
© Prognoz Technologies Pvt. Ltd
Declaring Objects
Obtaining objects of a class is a two-stage process:
1) Declare a variable of the class type:
Box myBox;
The value of myBox is a reference to an object, if one exists, or null.
At this moment, the value of myBox is null.
2) Acquire an actual, physical copy of an object and assign its address to
the variable. How to do this?
© Prognoz Technologies Pvt. Ltd
Operator new
Allocates memory for a Box object and returns its address:
Box myBox = new Box();
The address is then stored in the myBox reference variable.
Box() is a class constructor - a class may declare its own constructor or
rely on the default constructor provided by the Java environment.
Syntax:
accessing data member of the class: objectname.datamember name;
accessing methods of the class: objectname.method name();
So for accessing data of the class: we have to use (.) dot operator.
© Prognoz Technologies Pvt. Ltd
Memory Allocation
Memory is allocated for objects dynamically.
This has both advantages and disadvantages:
1) as many objects are created as needed
2) allocation is uncertain – memory may be insufficient
Variables of simple types do not require new:
int n = 1;
In the interest of efficiency, Java does not implement simple types as
objects. Variables of simple types hold values, not references.
© Prognoz Technologies Pvt. Ltd
Assigning Reference Variables
Assignment copies address, not the actual value:
Box b1 = new Box();
Box b2 = b1;
Both variables point to the same object.
Variables are not in any way connected. After
b1 = null;
b2 still refers to the original object.
© Prognoz Technologies Pvt. Ltd
Thank you!!
20

More Related Content

What's hot

Oop in kotlin
Oop in kotlinOop in kotlin
Encapsulation
EncapsulationEncapsulation
Encapsulation
Githushan Gengaparam
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Encapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistenceEncapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistence
Prem Lamsal
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented conceptschristradus
 
C++ with student management system project
C++ with student management system projectC++ with student management system project
C++ with student management system project
Kratik Khandelwal
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
Nikhil Agrawal
 
Oops
OopsOops
OOP
OOPOOP
Oop concepts
Oop conceptsOop concepts
Oop concepts
Ritu Mangla
 
Oops slide
Oops slide Oops slide
Oops slide
Ashok Sharma
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 

What's hot (20)

Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Oops
OopsOops
Oops
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Concept of Object Oriented Programming
Concept of Object Oriented Programming Concept of Object Oriented Programming
Concept of Object Oriented Programming
 
Characteristics of oop
Characteristics of oopCharacteristics of oop
Characteristics of oop
 
General oops concepts
General oops conceptsGeneral oops concepts
General oops concepts
 
Ashish oot
Ashish ootAshish oot
Ashish oot
 
Encapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistenceEncapsulation of operations, methods & persistence
Encapsulation of operations, methods & persistence
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
C++ with student management system project
C++ with student management system projectC++ with student management system project
C++ with student management system project
 
javaopps concepts
javaopps conceptsjavaopps concepts
javaopps concepts
 
Oops
OopsOops
Oops
 
Oop concept
Oop conceptOop concept
Oop concept
 
OOP
OOPOOP
OOP
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Oops slide
Oops slide Oops slide
Oops slide
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
encapsulation
encapsulationencapsulation
encapsulation
 

Similar to Basic concept of Object Oriented Programming

JS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.pptJS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.ppt
MadhukarReddy74
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
NuurAxmed2
 
OOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptxOOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptx
ShobhitSrivastava15887
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
Mahmoud Alfarra
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)dannygriff1
 
Object oriented programming tutorial
Object oriented programming tutorialObject oriented programming tutorial
Object oriented programming tutorial
Ghulam Abbas Khan
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
The Ring programming language version 1.7 book - Part 77 of 196
The Ring programming language version 1.7 book - Part 77 of 196The Ring programming language version 1.7 book - Part 77 of 196
The Ring programming language version 1.7 book - Part 77 of 196
Mahmoud Samir Fayed
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
ArpitaJana28
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
ethiouniverse
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
Usman Mehmood
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
Saravanakumar viswanathan
 
Object Oriented Programming.pptx
 Object Oriented Programming.pptx Object Oriented Programming.pptx
Object Oriented Programming.pptx
ShuvrojitMajumder
 

Similar to Basic concept of Object Oriented Programming (20)

Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
JS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.pptJS-02-JavaScript-Objects.ppt
JS-02-JavaScript-Objects.ppt
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
OOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptxOOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptx
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)
 
Object oriented programming tutorial
Object oriented programming tutorialObject oriented programming tutorial
Object oriented programming tutorial
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Java basics
Java basicsJava basics
Java basics
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 
The Ring programming language version 1.7 book - Part 77 of 196
The Ring programming language version 1.7 book - Part 77 of 196The Ring programming language version 1.7 book - Part 77 of 196
The Ring programming language version 1.7 book - Part 77 of 196
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
Object Oriented Programming.pptx
 Object Oriented Programming.pptx Object Oriented Programming.pptx
Object Oriented Programming.pptx
 

More from Prognoz Technologies Pvt. Ltd.

Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
Prognoz Technologies Pvt. Ltd.
 
A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net  A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net
Prognoz Technologies Pvt. Ltd.
 
Microsoft C# programming basics
Microsoft C# programming basics  Microsoft C# programming basics
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
Introduction of .net framework
Introduction of .net frameworkIntroduction of .net framework
Introduction of .net framework
Prognoz Technologies Pvt. Ltd.
 
How to handle exceptions in Java Technology
How to handle exceptions in Java Technology How to handle exceptions in Java Technology
How to handle exceptions in Java Technology
Prognoz Technologies Pvt. Ltd.
 
Features of java technology
Features of java technologyFeatures of java technology
Features of java technology
Prognoz Technologies Pvt. Ltd.
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
Prognoz Technologies Pvt. Ltd.
 
Qualities of a Successful Person
Qualities of a Successful PersonQualities of a Successful Person
Qualities of a Successful Person
Prognoz Technologies Pvt. Ltd.
 
Quantitative Aptitude Concepts
Quantitative Aptitude ConceptsQuantitative Aptitude Concepts
Quantitative Aptitude Concepts
Prognoz Technologies Pvt. Ltd.
 

More from Prognoz Technologies Pvt. Ltd. (9)

Introduction to package in java
Introduction to package in javaIntroduction to package in java
Introduction to package in java
 
A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net  A comprehensive software infrastructure of .Net
A comprehensive software infrastructure of .Net
 
Microsoft C# programming basics
Microsoft C# programming basics  Microsoft C# programming basics
Microsoft C# programming basics
 
Introduction of .net framework
Introduction of .net frameworkIntroduction of .net framework
Introduction of .net framework
 
How to handle exceptions in Java Technology
How to handle exceptions in Java Technology How to handle exceptions in Java Technology
How to handle exceptions in Java Technology
 
Features of java technology
Features of java technologyFeatures of java technology
Features of java technology
 
Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming Interesting Concept of Object Oriented Programming
Interesting Concept of Object Oriented Programming
 
Qualities of a Successful Person
Qualities of a Successful PersonQualities of a Successful Person
Qualities of a Successful Person
 
Quantitative Aptitude Concepts
Quantitative Aptitude ConceptsQuantitative Aptitude Concepts
Quantitative Aptitude Concepts
 

Recently uploaded

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Basic concept of Object Oriented Programming

  • 1. © Prognoz Technologies Pvt. Ltd Object & Class
  • 2. © Prognoz Technologies Pvt. Ltd What is Object ?  Objects are key to understanding object-oriented technology.  Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle. 2
  • 3. © Prognoz Technologies Pvt. Ltd Continue…  Real-world objects share two characteristics: They all have state and behavior.  Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail).
  • 4. © Prognoz Technologies Pvt. Ltd Continue… Bicycles also have state(current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). 4
  • 5. © Prognoz Technologies Pvt. Ltd What is Class ?  In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model.  Each bicycle was built from the same set of blueprints and therefore contains the same components.  In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles.  A class is the blueprint from which individual objects are created.
  • 6. © Prognoz Technologies Pvt. Ltd Continue…
  • 7. © Prognoz Technologies Pvt. Ltd Continue… OBJECTS CLASSES
  • 8. © Prognoz Technologies Pvt. Ltd A Class acts as the template from which an instance of an object is created. The class defines the properties of the object and the methods used to control the object's behavior. A Class specifies the structure of data as well as the methods which manipulate that data. Such data and methods are contained in each instance of the class. A Class is a model or template that can be instantiated to create objects with a common definition, and therefore common properties, operations and behavior. A Class provides a template for defining the behavior of a particular type of object. Objects are referred to as “instances” of a class.
  • 9. © Prognoz Technologies Pvt. Ltd CLASSES class One { } class Book { } class College { } class AnyThing { }
  • 10. © Prognoz Technologies Pvt. Ltd Class Definition A class contains a name, several variable declarations (instance variables) and several method declarations. All are called members of the class. General form of a class: class classname { type instance-variable-1; … type instance-variable-n; type method-name-1(parameter-list) { type method-name-2(parameter-list) { … type method-name-m(parameter-list) { … }
  • 11. © Prognoz Technologies Pvt. Ltd Example: Class A class with three variable members: class Box { double width; double height; double depth; } A new Box object is created and a new value assigned to its width variable: Box myBox = new Box(); myBox.width = 100;
  • 12. © Prognoz Technologies Pvt. Ltd Example: Class Usage class BoxDemo { public static void main(String args[] Box mybox = new Box(); double vol; mybox.width = 10; mybox.height = 20; mybox.depth = 15; vol = mybox.width * mybox.height * m System.out.println("Volume is " + } }
  • 13. © Prognoz Technologies Pvt. Ltd Compilation and Execution Place the Box class definitions in file Box.java: class Box { … } Place the BoxDemo class definitions in file BoxDemo.java: class BoxDemo { public static void main(…) { … } } Compilation and execution: > javac BoxDemo.java > java BoxDemo
  • 14. © Prognoz Technologies Pvt. Ltd Variable Independence Each object has its own copy of the instance variables: changing the variables of one object has no effect on the variables of another object.
  • 15. © Prognoz Technologies Pvt. Ltd OBJECTS class Book { } class JavaBook { public ststic void main(String args[]) { Book b=new Book(); } }
  • 16. © Prognoz Technologies Pvt. Ltd Declaring Objects Obtaining objects of a class is a two-stage process: 1) Declare a variable of the class type: Box myBox; The value of myBox is a reference to an object, if one exists, or null. At this moment, the value of myBox is null. 2) Acquire an actual, physical copy of an object and assign its address to the variable. How to do this?
  • 17. © Prognoz Technologies Pvt. Ltd Operator new Allocates memory for a Box object and returns its address: Box myBox = new Box(); The address is then stored in the myBox reference variable. Box() is a class constructor - a class may declare its own constructor or rely on the default constructor provided by the Java environment. Syntax: accessing data member of the class: objectname.datamember name; accessing methods of the class: objectname.method name(); So for accessing data of the class: we have to use (.) dot operator.
  • 18. © Prognoz Technologies Pvt. Ltd Memory Allocation Memory is allocated for objects dynamically. This has both advantages and disadvantages: 1) as many objects are created as needed 2) allocation is uncertain – memory may be insufficient Variables of simple types do not require new: int n = 1; In the interest of efficiency, Java does not implement simple types as objects. Variables of simple types hold values, not references.
  • 19. © Prognoz Technologies Pvt. Ltd Assigning Reference Variables Assignment copies address, not the actual value: Box b1 = new Box(); Box b2 = b1; Both variables point to the same object. Variables are not in any way connected. After b1 = null; b2 still refers to the original object.
  • 20. © Prognoz Technologies Pvt. Ltd Thank you!! 20