Welcome to the Object-Oriented Programming (OOP) tutorial! OOP is a programming paradigm based on the concept of "objects", which can contain data in the form of fields (often known as attributes or properties) and code in the form of procedures (often known as methods).

Basic Concepts

  • Class: A blueprint for creating objects. It defines the properties and behaviors that the objects of the class will have.
  • Object: An instance of a class. Objects are created from classes and can hold unique data and behavior.
  • Encapsulation: The concept of hiding the internal state of an object and requiring all interaction to be performed through an object's methods.
  • Inheritance: The ability to create new classes that are derived from existing classes. The new class inherits the properties and methods of the parent class.
  • Polymorphism: The ability to treat objects of different classes in a unified manner.

Example

Here's a simple example of a class in Python:

class Dog:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def bark(self):
        return f"{self.name} says: Woof!"

# Creating an object of the Dog class
my_dog = Dog("Buddy", 5)

# Accessing the object's properties and methods
print(my_dog.name)  # Output: Buddy
print(my_dog.age)   # Output: 5
print(my_dog.bark()) # Output: Buddy says: Woof!

Further Reading

For more information on OOP, you can visit our Advanced OOP Tutorial.

Dog