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

Computer Programming Lec1

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

Computer Programming Lec1

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

Computer Engineering Department Computer

Programing
‫م دعاء خالد عبد الرضا‬.‫م‬

first Stage
2024-2023
Lecture 1
Introduction to OOP concepts
Object-oriented programming
• is a programming approach that aims to organize programs by
breaking them down into a set of objects that interact with each
other.
• Object-oriented programming is characterized by its focus on objects,
which are entities that represent concepts and things in reality, such
as cars, employees, books, and others.
• Each object carries certain properties and can perform specific
actions
Oop includes several key concepts:
1. Objects: are the actual objects that represent program concepts
and carry data and behavior.

2. Classes: are templates for creating objects, specifying their behavior


and properties.

❖Simply put, objects are the things we work with in a program, while
classes are the structures that define how objects are structured and
behave
Objects and Classes
• Example1:
class person:
def __init__(self,name):
self.name =name
person1=person(“ali")
print(person1.name)
#output: ali
Objects and Classes
In this example:
•We define a class called Person.
•The class has a constructor method _init_ that initializes the person’s
name attribute.
•We create an instance of the Person class named person1 with the
name “ali”.
•We access and print the name attribute of the person1 object, which
outputs “ali”.
Objects and Classes
Example2:
class dog:
def _ init _(self ,name, breed):
self.name =name
self . breed = breed
def bark(self):
return"woof!"
dog1 = dog("buddy","golden retrever")
dog2 = dog("max","labrador")

print(f"{dog1.name} is a{dog1.breed}") Output:


print(f"{dog2.name} is a{dog2.name}") buddy is agolden retrever
print(dog1.bark()) max is alabrador
print(dog2.bark()) woof!
woof!
Objects and Classes
❖ inThis code:
❖ defines a class called "Dog" with attributes for the dog's name and breed, and
a method to make the dog bark. It creates two instances of the Dog class, sets
their attributes, and calls the bark method to make them bark.

You might also like