Object Oriented Programming
INTRODUCTION TO OOP
Introduction to OOP
• Creating objects
• Contain both data and methods
Advantages:
• Faster and easier to execute
• Provides a clear structure for the programs
• Helps to keep the Java code DRY "Don't Repeat Yourself", and
makes the code easier to maintain, modify and debug
• Makes it possible to create full reusable applications with less
code and shorter development time
Two Main Aspects
Class Objects
Class
• A way of organizing information about a type of data
so a programmer can reuse elements when making
multiple instances of that data type
• A user-defined type that describes what a certain
type of object will look like
Object
• A collection of related data and/or functionality
• The object is an instance of a class
Class Vs Object
Class Object
A class is a template for creating objects in
The object is an instance of a class.
program.
A class is a logical entity Object is a physical entity
A class does not allocate memory space when it is Object allocates memory space whenever they
created. are created.
You can create more than one object using a
You can declare class only once.
class.
Example: Car. Example: Jaguar, BMW, Tesla, etc.
Class generates objects Objects provide life to the class.
Simple Code Declaring a class
Creating an object