0% found this document useful (0 votes)
40 views7 pages

Write One Page On Object Oriented Programming?

The document provides information about object-oriented programming (OOP) concepts like abstraction, encapsulation, polymorphism, and inheritance. It also discusses the differences between a class and structure in C++. An object is defined as a data field with unique attributes and behaviors defined by member variables and methods. Examples are provided of creating a MyClass with attributes that can be accessed by objects, and defining methods both inside and outside the class.

Uploaded by

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

Write One Page On Object Oriented Programming?

The document provides information about object-oriented programming (OOP) concepts like abstraction, encapsulation, polymorphism, and inheritance. It also discusses the differences between a class and structure in C++. An object is defined as a data field with unique attributes and behaviors defined by member variables and methods. Examples are provided of creating a MyClass with attributes that can be accessed by objects, and defining methods both inside and outside the class.

Uploaded by

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

Name: Muhammad Ali

ID NO: 12249
Section: ES
Subject: OOP
Teacher: Muhammad ASAD
Writing

1. Write one page on Object oriented programming?


Object-oriented programming (OOP) is a computer programming model that
organizes software design around data, or objects, rather than functions and logic.
Object oriented programming is a way of giving more importance to the data than
the sequence of the code.

The real world is a collection of objects which interact with each other to form an
environment. These objects have certain features and certain functions that define
the object the way it is.

For example, a microwave oven has certain features, such as it’s model number, it’s
capacity, the current heating temperature etc. It’s function includes switching on,
heating it’s contents, setting the timer, etc.

In programming, the microwave can be an object with it’s features as it’s data
members and it’s functions as it’s member functions.

Looking deeper,

The features of a microwave can be altered only by it’s functional units and not by
anyone or anything external to the microwave itself. This is true in programming
sense too. This is also known as abstraction and encapsulation.

Abstraction is the process of hiding data that is not necessary for the user to know
about. The internal working of a microwave needn’t be known to us for it’s
operation.

Encapsulation is the concept of binding the data members along with it’s member
functions into one single unit, as the name suggests. The working of a microwave can
only be controlled by it’s member functions, i.e. the buttons.
Object oriented programming involves several concepts:

 Abstraction
 Encapsulation
 Polymorphism
 Modularity
 Inheritance

2. What is the difference between a Structure and a Class?


Answer :-
In C++, a structure is same as class except the following differences:
1. Members of a class are private by default and members of struct are
public by default.
2. When deriving a struct from a class/struct, default access-specifier for
a base class/struct is public. And when deriving a class, default access
specifier is private.
3. There is no data hiding features comes with structures. Classes do,
private, protected and public.
4. A structure is contains only data member, but class contain data
member and member function.
5. In a Structure we can't initialize the value to the variable but in class
variable we assign the values.

a. struct T : Base // same thing as "struct T :


public Base"
b. {
c. ...
d. };
e. class T : Base // same thing as "class T : private
Base"
f. {
g. ...
h. };

3. What is an Object of a class in OOP?


Answer :-
An object can be defined as a data field that has unique attributes and
behavior. Object is a software "bundle" consisting of a set of variables which
define the states the object can exist in and a set of functions that define the
behavior of that object. Software objects are often used to model the real-world
objects that you find in everyday life.The "objects" used to create an OOP
program are classes and structures. A class groups together a number of related
fields (member variables) of different data types which define the State of the
object, and a number of Methods (functions) which define the Behavior of the
object and ways of modifying the object's state. . A simple example of an object
would be a person. Logically, you would expect a person to have a name. This
would be considered a property of the person. You could also expect a person to
be able to do something, such as walking or driving. This would be considered a
method of the person. 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.

C++ programming
4. Create a class called “MyClass”.
Answer :-
Source code:-

5. Create an object called “myObj” in main and access the attributes.


6. Create multiple objects of one class

Answer :-
7. Define a function inside the class, and we name it " myMethodin".
Answer :-
8. Define a function outside the class, and we name it " myMethodout".
Answer :-

You might also like