0% found this document useful (0 votes)
68 views13 pages

AKASH CHOWDHURY - Oops

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

AKASH CHOWDHURY - Oops

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

TOPIC : OBJECT AND CLASS IN OOPs

PAPER NAME : OBJECT ORIENTED PROGRAMMING


PAPER CODE : PCC CS 503
NAME : AKASH CHOWDHURY
ROLL NO. : 18700121018
STREAM : CSE – A
YEAR : 3RD
SEMESTER : 5TH
INDEX
Topic Slides
Introduction 3
Class 4
Object 5
Class Members 6
Access Modifiers 7
Constructors 8
Inheritance 9
Polymorphism 10
Abstraction 11
Encapsulation 12
INTRODUCTION TO OOPS

Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or
objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior. OOP
focuses on the objects that developers want to manipulate rather than the logic required to manipulate them.

Advantages of Object oriented programming :-


1. Troubleshooting is easier with the OOP language
2. Code Reusability
3. Productivity
4. Data Redundancy
5. Code Flexibility
6. Solving problems
7. Security
CLASS

A class is a user defined layout or blueprint of an object that describes what a specific kind of object will look like. A class is
a blueprint that defines the variables and the method common to all objects of a certain kind. It helps us to bind data and
methods together making code reusable unlike procedure language.

A class has mainly two members know as class members :

1. Attributes (data members)

2. Methods (member functions)

Syntax:

<Access specifier> class <class name> {

//code}
OBJECT
An entity that has state and behavior is known as an object. An object is an instance of a class. An object does not have a
name in essence but it is referred to by a reference variable which has a name
An object has three characteristics:
• State: represents the data (value) of an object.
• Behavior: represents the behavior (functionality) of an object .
• Identity: An object identity is typically implemented via a unique ID. The value of the ID is not visible to the external
user. However, it is used internally by the JVM to identify each object uniquely.

Syntax for object creation :

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


CLASS MEMBERS: ATTRIBUTES AND
METHODS
Attributes or Data members : Variables declared within a class preceded by a data type which define the state of an object
are called data members.
Methods or Member methods: Method or function which define the behavior of an object of that class are called member
functions or member methods.
Methods and attributes uses variables for different purposes such as storing , calculation etc. They are of two types :
1. Instance variable : It is basically a class variable without a static modifier and is usually shared by all class instances.
Across different objects, these variables can have different values.
2. Class variable : It is basically a static variable that can be declared
anywhere at class level with static. Across different objects, these variables
can have only one value.
ACCESS MODIFIERS
Access modifiers are object-oriented programming that is used to set the accessibility of classes, constructors, methods, and
other members of Java. Using the access modifiers we can set the scope or accessibility of these classes, methods,
constructors, and other members.

Types of Access modifiers :

• Private: We can access the private modifier only within the same class and not from outside the class.

• Default: We can access the default modifier only within the same package and not from outside the package. And also, if
we do not specify any access modifier it will automatically consider it as default.

• Protected: We can access the protected modifier within the same package and also from outside the package with the help
of the child class.

• Public: We can access the public modifier from anywhere.


CONSTRUCTORS
Constructor in java is used to create the instance of the class. Constructors are almost similar to methods except for two things - its
name is the same as the class name and it has no return type.
Constructor overloading: It can be defined as the concept of having more than one constructor with different parameters so that every
constructor can perform a different task.
There are 3 types of constructors :
1. Parameterized constructor : A constructor which has a specific number of parameters is called a parameterized constructor. The
parameterized constructor is used to provide different values to distinct objects. Syntax :: <class name>(<data>) { }.

2. Non parameterized constructor : A constructor is called "Default Constructor" when it


doesn't have any parameter. The default constructor is used to provide the default values
to the object like 0, null, etc., depending on the type. Syntax :: <class name>(){}.

3. Copy constructor: A particular type of constructor that we use to create a


duplicate (exact copy) of the existing object of a class.
Syntax :: <class name>(<class name><object name>){}.
INHERITANCE

Inheritance in Java is a mechanism in which one object acquires all the properties and behaviors of a parent object. It is an
important part of OOPs he idea behind inheritance in Java is that you can create new classes that are built upon existing
classes. When you inherit from an existing class, you can reuse methods and fields of the parent class. Moreover, you can
add new methods and fields in your current class also.

Syntax : class <sub class name> extends <super class name>

// code

}
POLYMORPHISM

Polymorphism is considered one of the important features of Object-Oriented Programming. Polymorphism allows us to
perform a single action in different ways. In other words, polymorphism allows you to define one interface and have
multiple implementations. The word “poly” means many and “morphs” means forms, So it means many forms.
There are two types of polymorphism in java :
1. Compile-Time Polymorphism :It is also known as static polymorphism. This type of polymorphism is achieved by
function overloading or operator overloading.
2. Runtime Polymorphism : It is also known as Dynamic Method Dispatch.
It is a process in which a function call to the overridden method is resolved
at Runtime. This type of polymorphism is achieved by Method Overriding.
ABSTRACTION

Data Abstraction may also be defined as the process of identifying only the required characteristics of an object ignoring the
irrelevant details. The properties and behaviors of an object differentiate it from other objects of similar type and also help
in classifying/grouping the objects. Abstraction can be achieved with either abstract classes or interfaces.

The abstract keyword is a non-access modifier, used for classes and methods:

1. Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another
class).
2. Abstract method: can only be used in an abstract class, and
it does not have a body. The body is provided by the subclass
(inherited from).
ENCAPSULATION

Encapsulation in Java is a process of wrapping code and data together into a single unit, for example, a capsule which is
mixed of several medicines. We can create a fully encapsulated class in Java by making all the data members of the class
private. Now we can use setter and getter methods to set and get the data in it. The Java Bean class is the example of a fully
encapsulated class.
REFERENCES

Information for the project has been taken from the following website :
• www.google.com
• www.wikipedia.com
• www.GeekforGeeks.com

You might also like