OOPs Class-2

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 123:-  OOPs Class-2 

Certainly! Let's delve deeper into Object-Oriented Programming (OOP) with some advanced concepts and examples.

1. Access Modifiers: Access modifiers control the visibility and accessibility of class members (attributes and methods). The three main access modifiers are:

  • Public: Members are accessible from anywhere.
  • Private: Members are only accessible within the class.
  • Protected: Members are accessible within the class and its subclasses.

pythonCopy code

class Person: def __init__(self, name, age): self.name = name # Public attribute self._age = age # Protected attribute self.__address = None # Private attribute def get_address(self): return self.__address def set_address(self, address): self.__address = address # Example usage person = Person("Alice", 30) print(person.name) print(person._age) # Protected attribute can still be accessed person.set_address("123 Main St") print(person.get_address())

2. Constructors and Destructors: Constructors are special methods used to initialize objects when they are created. Destructors are used to perform cleanup operations before an object is destroyed.

pythonCopy code

class MyClass: def __init__(self, value): self.value = value print("Constructor called") def __del__(self): print("Destructor called") obj1 = MyClass(10) obj2 = MyClass(20) del obj1 del obj2

3. Method Overriding: Method overriding allows a subclass to provide a specific implementation for a method that is already defined in its superclass.

pythonCopy code

class Shape: def area(self): pass class Circle(Shape): def __init__(self, radius): self.radius = radius def area(self): return 3.14 * self.radius * self.radius class Square(Shape): def __init__(self, side): self.side = side def area(self): return self.side * self.side # Example usage circle = Circle(5) square = Square(4) print("Circle area:", circle.area()) print("Square area:", square.area())

4. Interfaces and Abstract Classes: An interface defines a contract that concrete classes must adhere to. An abstract class is a class that cannot be instantiated and is meant to be subclassed.

pythonCopy code

from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass class Circle(Shape): def __init__(self, radius): self.radius = radius def area(self): return 3.14 * self.radius * self.radius class Square(Shape): def __init__(self, side): self.side = side def area(self): return self.side * self.side # Example usage circle = Circle(5) square = Square(4) print("Circle area:", circle.area()) print("Square area:", square.area())

These advanced concepts build upon the foundational concepts of OOP and enable you to create more sophisticated and modular code. Keep in mind that these examples are in Python, but similar concepts exist in other object-oriented programming languages like Java, C++, and C#. OOP helps you design and build software systems that are easier to understand, maintain, and extend.

17. OOPs

Comments: 2

profile
@mk.info.work
17-Feb-2024, 10:20 PM

SCIAKU Team please upload 1st video of TREE please please please, please

profile
@na3744
23-Feb-2024, 02:52 AM

I bought this course, it worth it!

profile
@mk.info.work
15-Nov-2023, 10:25 PM

Hi i want to buy this course but you dont have master card payment method please let me know how i can buy it

profile
@sciaku1
11-Jan-2024, 03:23 PM

Dear mk.info.work, Now we have all types of payment options. If you need to purchase just checkout our official website

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?