SlideShare a Scribd company logo
1 of 26
OBJECT ORIENTED PROGRAMING
{OOP}
BY SANGA G,
OOP ITRODUCTION
• What is object oriented programming?
Object-oriented programming (OOP) is a way to
organize and conceptualize a program as a set
of interacting objects.
• The programmer defines the types of objects
that will exist.
• The programmer creates object instances as
they are needed.
OOP CONT………….
• The programmer specifies how these various
object will communicate and interact with each
other.
• Object-oriented programming is a methodology
that gives programmers tools to make this
modeling process easier.
• Simply we can say Object-oriented
programming, or OOP, is an approach to problem
solving where all computations are carried out
using objects.
TEMINOLOGIES USED IN OOP
• Object
• Class
• Instance
• Inheritance
• Encapsulation
• Abstraction
• Polymorphism
• Overloading
Object
• An object is a component of a program that
knows how to perform certain actions and
how to interact with other elements of the
program.
• An object contains both data and methods
that manipulate that data
– An object is active, not passive; (it does things)
– An object is responsible for its own data
Object
• Code in object-oriented programming is organized
around objects. Once you have your objects, they can
interact with each other to make something happen
• Let's say you want to have a program where a person
gets into a car and drives it from A to B. You would
start by describing the objects, such as a person and
car. That includes methods: a person knows how to
drive a car and a car knows what it is like to be driven.
Once you have your objects, you bring them together
so the person can get into the car and drive.
Class
• A class is a blueprint or template or set of
instructions to build a specific type of object.
or
• class is the generic definition for a set of
similar objects
• A class can be thought of as a template used
to create a set of objects.
• A class is a static definition; a piece of code
written in a programming language
Class
• So, let's say you want to use a person in your
program. You want to be able to describe the
person and have the person do something. A
class called 'person' would provide a blueprint
for what a person looks like and what a person
can do. To actually use a person in your
program you need to create an object. You use
the person class to create an object of the
type 'person.' Now you can describe this
person and have it do something.
Class
A class is a statement
class ClassVariable
attr
AttrName1
:
AttrNameN
meth Pattern1 Statement end
:
meth PatternN Statement end
end
Instance
• An instance is a realization of a particular item of a class. In
other words, an instance is an instantiation of a class. All
the instances of a class have similar properties, as
described in the class definition. For example, you can
define a class called "Student" and create three instances
of the class "Student" for "Peter", "Paul" and "Pauline".
• The term "object" usually refers to instance. But it is often
used loosely, and may refer to a class or an instance.
• instance is a concrete occurrence of any object, existing
usually during the runtime of a computer program
Example of instance
For examples, suppose that we have a class called Circle, we can create
instances of Circle as follows:
// Declare 3 instances of the class Circle, c1, c2, and c3
Circle c1, c2, c3; // They hold a special value called null
// Construct the instances via new operator
c1 = new Circle();
c2 = new Circle(2.0);
c3 = new Circle(3.0, "red");
// You can Declare and Construct in the same statement Circle
c4 = new Circle();
Inheritance
• Inheritance
• Inheritance is the process of forming a new
class from an existing class that is from the
existing class called as base class, new class is
formed called as derived class.
• This is a very important concept of object-
oriented programming since this feature helps
to reduce the code size.
Example
// A class to display the attributes of the vehicle
class Vehicle {
String color;
int speed;
int size;
void attributes() {
System.out.println("Color : " + color);
System.out.println("Speed : " + speed);
System.out.println("Size : " + size);
}
}
// A subclass which extends for vehicle class
Car extends Vehicle {
int CC;
int gears;
void attributescar() {
Example cont……
// The subclass refers to the members of the superclass
System.out.println("Color of Car : " + color);
System.out.println("Speed of Car : " + speed);
System.out.println("Size of Car : " + size);
System.out.println("CC of Car : " + CC);
System.out.println("No of gears of Car : " + gears);
}
}
public class Test {
public static void main(String args[]) {
Car b1 = new Car();
b1.color = "Blue";
b1.speed = 200 ;
b1.size = 22;
b1.CC = 1000;
b1.gears = 5;
b1.attributescar();
}
}
Encapsulation
• Encapsulation is placing the data and the
functions that work on that data in the same
place. While working with procedural
languages, it is not always clear which
functions work on which variables but object-
oriented programming provides you
framework to place the data and the relevant
functions together in the same object.
Benefits of Encapsulation
• Makes it easy to model real-world entities –
hence easy to understand and maintain
• Control the way data is accessed or modified
• Makes the class easy to use for clients
• Increase reusability
• Aids to the flexibility of design e.g. It is
possible to add accelerationConfiguration field
in the Car. This will enable you to have
different acceleration behaviour of each car.
Abstraction
• Polymorphism is the capability of a method to
do different things based on the object that it
is acting upon. In other words, polymorphism
allows you define one interface and have
multiple implementations
Overloading
• Overloading is ability of one function to
perform different tasks, i.e,it allows creating
several methods with the same name which
differ from each other in the type of the input
and the output of the function.
Private and public
• Public, means all the class members declared under public will be
available to everyone. The data members and member functions
declared public can be accessed by other classes too. Hence there
are chances that they might change them. So the key members
must not be declared public.
example
class PublicAccess
{
public:
// public access specifier
int x;
// Data Member Declaration
void display();
// Member Function decaration
}
Private
• Private , means that no one can access the
class members declared private outside that
class. If someone tries to access the private
member, they will get a compile time error. By
default class variables and member functions
are private.
Methods and properties of the class
• A method in object-oriented programming
(OOP) is a procedure associated with a
message and an object. An object is made up
of data and behavior, which form the interface
that an object presents to the outside world.
Data is represented as properties of the object
and behavior as methods. For example, a
Window object would have methods such as
open and close, while its state (whether it is
opened or closed) would be a property.
Class methods
• Class methods are methods that are called on
a class rather than an instance. They are
typically used as part of an object meta-
model. I.e, for each class defined an instance
of the class object in the meta-model is
created.
property
• property is a member of a class that plays an
intermediary role to a field of the class. For example, if
you have a field of class and that member represents
the salary of an employee, a property can be the
"door" that other classes that need the salary must
present their requests to. As such, these external
classes cannot just change the salary or retrieve it as
they wish. A property can be used to validate their
request, to reject or to accept them.
• A property is used to "filter" access to a field of a class.
Therefore, you start by declaring a (private (if you don't
make it private, you may be deceiving the purpose of
creating a property)) field
property
• A property is used to "filter" access to a field
of a class. Therefore, you start by declaring a
(private (if you don't make it private, you may
be deceiving the purpose of creating a
property)) field
• https://www3.ntu.edu.sg/home/ehchua/prog
ramming/java/J3a_OOPBasics.html
• https://processing.org/examples/inheritance.
html
• https://www.tutorialspoint.com/cplusplus/cp
p_data_encapsulation.htm

More Related Content

What's hot

Object oriented methodologies
Object oriented methodologiesObject oriented methodologies
Object oriented methodologies
naina-rani
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
Aida Ramlan II
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
Jay Patel
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
JSP Processing
JSP ProcessingJSP Processing
JSP Processing
Sadhana28
 

What's hot (20)

Object oriented methodologies
Object oriented methodologiesObject oriented methodologies
Object oriented methodologies
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming concepts
 
encapsulation
encapsulationencapsulation
encapsulation
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in Python
 
Object-Oriented Programming Concepts
Object-Oriented Programming ConceptsObject-Oriented Programming Concepts
Object-Oriented Programming Concepts
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
JSP Processing
JSP ProcessingJSP Processing
JSP Processing
 
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
 
object oriented Programming ppt
object oriented Programming pptobject oriented Programming ppt
object oriented Programming ppt
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Uml Common Mechanism
Uml Common MechanismUml Common Mechanism
Uml Common Mechanism
 
Lecture 1 oop
Lecture 1 oopLecture 1 oop
Lecture 1 oop
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
OOP - Benefits and advantages of OOP
OOP - Benefits and advantages of OOPOOP - Benefits and advantages of OOP
OOP - Benefits and advantages of OOP
 

Viewers also liked

Mofolojia ya kiswahili
Mofolojia ya kiswahiliMofolojia ya kiswahili
Mofolojia ya kiswahili
Geophery sanga
 
Project object explain your choice
Project object   explain your choiceProject object   explain your choice
Project object explain your choice
Soren
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
Jay Patel
 
Ge 249 SOPHISTS GROUP SAUT BUKOBA
Ge 249 SOPHISTS GROUP SAUT BUKOBA Ge 249 SOPHISTS GROUP SAUT BUKOBA
Ge 249 SOPHISTS GROUP SAUT BUKOBA
Mwl. Mapesa Nestory
 
Uchumi wa kibiblia
Uchumi wa kibibliaUchumi wa kibiblia
Uchumi wa kibiblia
001111111111
 
Futuristic programing language
Futuristic programing languageFuturistic programing language
Futuristic programing language
Mohamed Zaki
 

Viewers also liked (20)

Object Oriented Programing - Intro
Object Oriented Programing - IntroObject Oriented Programing - Intro
Object Oriented Programing - Intro
 
Mofolojia ya kiswahili
Mofolojia ya kiswahiliMofolojia ya kiswahili
Mofolojia ya kiswahili
 
Project object explain your choice
Project object   explain your choiceProject object   explain your choice
Project object explain your choice
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
 
Ge 249 SOPHISTS GROUP SAUT BUKOBA
Ge 249 SOPHISTS GROUP SAUT BUKOBA Ge 249 SOPHISTS GROUP SAUT BUKOBA
Ge 249 SOPHISTS GROUP SAUT BUKOBA
 
Uchumi wa kibiblia
Uchumi wa kibibliaUchumi wa kibiblia
Uchumi wa kibiblia
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
OOPS features using Objective C
OOPS features using Objective COOPS features using Objective C
OOPS features using Objective C
 
Dynamics Telephony Dialer Intro
Dynamics Telephony Dialer IntroDynamics Telephony Dialer Intro
Dynamics Telephony Dialer Intro
 
Object Oriented Programing - Inheritance
Object Oriented Programing - InheritanceObject Oriented Programing - Inheritance
Object Oriented Programing - Inheritance
 
Object Oriented Programing - Polymrphism
Object Oriented Programing - PolymrphismObject Oriented Programing - Polymrphism
Object Oriented Programing - Polymrphism
 
Water resources management river basin manage
Water resources management river basin manageWater resources management river basin manage
Water resources management river basin manage
 
Futuristic programing language
Futuristic programing languageFuturistic programing language
Futuristic programing language
 
Aspect Oriented Programing - Introduction
Aspect Oriented Programing - IntroductionAspect Oriented Programing - Introduction
Aspect Oriented Programing - Introduction
 
Fursa kwa walio na mtaji mdogo
Fursa kwa walio na mtaji mdogoFursa kwa walio na mtaji mdogo
Fursa kwa walio na mtaji mdogo
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScript
 
Jipime Sayansi Darasa la Sita
Jipime Sayansi Darasa la SitaJipime Sayansi Darasa la Sita
Jipime Sayansi Darasa la Sita
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Uhusiano fonolojia vs mofolojia
Uhusiano fonolojia vs mofolojiaUhusiano fonolojia vs mofolojia
Uhusiano fonolojia vs mofolojia
 
LIDO勉強会#1
LIDO勉強会#1LIDO勉強会#1
LIDO勉強会#1
 

Similar to object oriented programing lecture 1

Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 

Similar to object oriented programing lecture 1 (20)

Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
80410172053.pdf
80410172053.pdf80410172053.pdf
80410172053.pdf
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
Oops
OopsOops
Oops
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptx
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
Principles of OOPs.pptx
Principles of OOPs.pptxPrinciples of OOPs.pptx
Principles of OOPs.pptx
 
OOP intro.ppt
OOP intro.pptOOP intro.ppt
OOP intro.ppt
 
C# by Zaheer Abbas Aghani
C# by Zaheer Abbas AghaniC# by Zaheer Abbas Aghani
C# by Zaheer Abbas Aghani
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

object oriented programing lecture 1

  • 2. OOP ITRODUCTION • What is object oriented programming? Object-oriented programming (OOP) is a way to organize and conceptualize a program as a set of interacting objects. • The programmer defines the types of objects that will exist. • The programmer creates object instances as they are needed.
  • 3. OOP CONT…………. • The programmer specifies how these various object will communicate and interact with each other. • Object-oriented programming is a methodology that gives programmers tools to make this modeling process easier. • Simply we can say Object-oriented programming, or OOP, is an approach to problem solving where all computations are carried out using objects.
  • 4. TEMINOLOGIES USED IN OOP • Object • Class • Instance • Inheritance • Encapsulation • Abstraction • Polymorphism • Overloading
  • 5. Object • An object is a component of a program that knows how to perform certain actions and how to interact with other elements of the program. • An object contains both data and methods that manipulate that data – An object is active, not passive; (it does things) – An object is responsible for its own data
  • 6. Object • Code in object-oriented programming is organized around objects. Once you have your objects, they can interact with each other to make something happen • Let's say you want to have a program where a person gets into a car and drives it from A to B. You would start by describing the objects, such as a person and car. That includes methods: a person knows how to drive a car and a car knows what it is like to be driven. Once you have your objects, you bring them together so the person can get into the car and drive.
  • 7. Class • A class is a blueprint or template or set of instructions to build a specific type of object. or • class is the generic definition for a set of similar objects • A class can be thought of as a template used to create a set of objects. • A class is a static definition; a piece of code written in a programming language
  • 8. Class • So, let's say you want to use a person in your program. You want to be able to describe the person and have the person do something. A class called 'person' would provide a blueprint for what a person looks like and what a person can do. To actually use a person in your program you need to create an object. You use the person class to create an object of the type 'person.' Now you can describe this person and have it do something.
  • 9. Class A class is a statement class ClassVariable attr AttrName1 : AttrNameN meth Pattern1 Statement end : meth PatternN Statement end end
  • 10. Instance • An instance is a realization of a particular item of a class. In other words, an instance is an instantiation of a class. All the instances of a class have similar properties, as described in the class definition. For example, you can define a class called "Student" and create three instances of the class "Student" for "Peter", "Paul" and "Pauline". • The term "object" usually refers to instance. But it is often used loosely, and may refer to a class or an instance. • instance is a concrete occurrence of any object, existing usually during the runtime of a computer program
  • 11. Example of instance For examples, suppose that we have a class called Circle, we can create instances of Circle as follows: // Declare 3 instances of the class Circle, c1, c2, and c3 Circle c1, c2, c3; // They hold a special value called null // Construct the instances via new operator c1 = new Circle(); c2 = new Circle(2.0); c3 = new Circle(3.0, "red"); // You can Declare and Construct in the same statement Circle c4 = new Circle();
  • 12. Inheritance • Inheritance • Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class. • This is a very important concept of object- oriented programming since this feature helps to reduce the code size.
  • 13. Example // A class to display the attributes of the vehicle class Vehicle { String color; int speed; int size; void attributes() { System.out.println("Color : " + color); System.out.println("Speed : " + speed); System.out.println("Size : " + size); } } // A subclass which extends for vehicle class Car extends Vehicle { int CC; int gears; void attributescar() {
  • 14. Example cont…… // The subclass refers to the members of the superclass System.out.println("Color of Car : " + color); System.out.println("Speed of Car : " + speed); System.out.println("Size of Car : " + size); System.out.println("CC of Car : " + CC); System.out.println("No of gears of Car : " + gears); } } public class Test { public static void main(String args[]) { Car b1 = new Car(); b1.color = "Blue"; b1.speed = 200 ; b1.size = 22; b1.CC = 1000; b1.gears = 5; b1.attributescar(); } }
  • 15. Encapsulation • Encapsulation is placing the data and the functions that work on that data in the same place. While working with procedural languages, it is not always clear which functions work on which variables but object- oriented programming provides you framework to place the data and the relevant functions together in the same object.
  • 16. Benefits of Encapsulation • Makes it easy to model real-world entities – hence easy to understand and maintain • Control the way data is accessed or modified • Makes the class easy to use for clients • Increase reusability • Aids to the flexibility of design e.g. It is possible to add accelerationConfiguration field in the Car. This will enable you to have different acceleration behaviour of each car.
  • 17. Abstraction • Polymorphism is the capability of a method to do different things based on the object that it is acting upon. In other words, polymorphism allows you define one interface and have multiple implementations
  • 18. Overloading • Overloading is ability of one function to perform different tasks, i.e,it allows creating several methods with the same name which differ from each other in the type of the input and the output of the function.
  • 19. Private and public • Public, means all the class members declared under public will be available to everyone. The data members and member functions declared public can be accessed by other classes too. Hence there are chances that they might change them. So the key members must not be declared public. example class PublicAccess { public: // public access specifier int x; // Data Member Declaration void display(); // Member Function decaration }
  • 20. Private • Private , means that no one can access the class members declared private outside that class. If someone tries to access the private member, they will get a compile time error. By default class variables and member functions are private.
  • 21.
  • 22. Methods and properties of the class • A method in object-oriented programming (OOP) is a procedure associated with a message and an object. An object is made up of data and behavior, which form the interface that an object presents to the outside world. Data is represented as properties of the object and behavior as methods. For example, a Window object would have methods such as open and close, while its state (whether it is opened or closed) would be a property.
  • 23. Class methods • Class methods are methods that are called on a class rather than an instance. They are typically used as part of an object meta- model. I.e, for each class defined an instance of the class object in the meta-model is created.
  • 24. property • property is a member of a class that plays an intermediary role to a field of the class. For example, if you have a field of class and that member represents the salary of an employee, a property can be the "door" that other classes that need the salary must present their requests to. As such, these external classes cannot just change the salary or retrieve it as they wish. A property can be used to validate their request, to reject or to accept them. • A property is used to "filter" access to a field of a class. Therefore, you start by declaring a (private (if you don't make it private, you may be deceiving the purpose of creating a property)) field
  • 25. property • A property is used to "filter" access to a field of a class. Therefore, you start by declaring a (private (if you don't make it private, you may be deceiving the purpose of creating a property)) field

Editor's Notes

  1. Th
  2. Class Car  A has all the features of a vehicle. But it has its own attributes which makes it different from other subclasses.