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

Object Oriented Programming - 1

Object Oriented Programming uses core concepts like: 1. Objects have properties and methods and programs are divided into objects. 2. Objects communicate with each other through functions. 3. Constructors initialize objects and give initial values to instance variables, performing start-up procedures. Encapsulation hides data implementation by restricting access to public methods while keeping instance variables private. Polymorphism allows a message to be displayed in multiple forms like a person having roles as father, husband, and employee. Inheritance allows classes to inherit features of other classes in a IS-A relationship.

Uploaded by

Mohamed Nader
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Object Oriented Programming - 1

Object Oriented Programming uses core concepts like: 1. Objects have properties and methods and programs are divided into objects. 2. Objects communicate with each other through functions. 3. Constructors initialize objects and give initial values to instance variables, performing start-up procedures. Encapsulation hides data implementation by restricting access to public methods while keeping instance variables private. Polymorphism allows a message to be displayed in multiple forms like a person having roles as father, husband, and employee. Inheritance allows classes to inherit features of other classes in a IS-A relationship.

Uploaded by

Mohamed Nader
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Object Oriented Programming

Prepared By: AMIT Learning


OOP Concepts

 The core of the pure object –oriented programming is to create an object

 An object that has certain properties and methods

 Programs are divided into what are known as objects

 Objects may communicate with each other through functions


Class versus object
Constructor

 A constructor initializes an object when it is created. It has the same name as its class and is syntactically similar to
a method. However, constructors have no explicit return type.
 Typically, you will use a constructor to give initial values to the instance variables defined by the class, or to perform
any other start-up procedures required to create a fully formed object.
 All classes have constructors, whether you define one or not, because Java automatically provides a default
constructor. However, once you define your own constructor, the default constructor is no longer used.
 Constructor name must be the same as its class name.
 A Constructor must have no explicit return type.
 A Java constructor cannot be abstract, static, final, and synchronized.
Encapsulation:

 The mechanism of hiding of data implementation by restricting access to public methods. Instance variables are
kept private and accessor methods are made public to achieve this. ( Setters & Getters)
Polymorphism:

 The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability
of a message to be displayed in more than one form.

 Real life example of polymorphism: A person at the same time can have different characteristic. Like a man at
the same time is a father, a husband, an employee. So the same person posses different behavior in different
situations. This is called polymorphism. ( Overloading & Overriding )
Inheritance

 the mechanism by which one class is allowed to inherit the features(fields and methods) of another class.

 Composition means HAS-A

 Inheritance means IS-A


 Example : Car has engine and Car is a machine.
This

 (this) is a reference variable that refers to the current object.


Abstraction

 abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to
the user. In other words, the user will have the information on what the object does instead of how it does it.

 Consider a real-life example of a man driving a car. The man only knows that pressing the accelerators will increase
the speed of car or applying brakes will stop the car but he does not know about how on pressing the accelerator
the speed is actually increasing, he does not know about the inner mechanism of the car or the implementation of
accelerator, brakes etc. in the car. This is what abstraction is.
Abstraction & interface

You might also like