Unit2_4.pptx Object Oriented Concepts .

priyankajadhav6600 224 views 25 slides Aug 12, 2024
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

Object Oriented Concepts
Defining class
Object of class
Access modifier
Feature of OOPs
Inheritance
Abstraction
Polymorphism
Encapsulation
2.2.1 Defining classes, class members, Interfaces, properties
2.2.2 Access modifiers, Implementation of class, interface and properties
2.2.3 Concept of hidi...


Slide Content

M. SC. (Computer Science) Course Code : 23CsCmpP121 Course Name : DOT NET Presented By : Priyanka Jadhav Modern College of Arts,Science and Commerce ,Pune-5

Notes Chapter 2 Introduction to C#

2.2 Object Oriented Concepts 2.2.1 Defining classes, class members, Interfaces, properties 2.2.2 Access modifiers, Implementation of class, interface and properties 2.2.3 Concept of hiding base class methods, Overriding 2.2.4 Event Handling Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Defining class Object of class Access modifier Feature of OOPs Inheritance Abstraction Polymorphism Encapsulation

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Access modifier Access modifiers are keywords used to specify the declared accessibility of a member or a type. Access modifiers are an integral part of object-oriented programming. They support the concept of encapsulation, which promotes the idea of hiding functionality. Access modifiers allow you to define who does or doesn't have access to certain features.

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Access modifier It’s special kind of modifiers using which we can define the scope of a type(class) and it’s members. Private Internal Protected Protected internal Public

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Access modifier

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Inheritance Inheritance is one of the three foundational principles of Object-Oriented Programming (OOP) because it allows the creation of hierarchical classifications. Using inheritance you can create a general class that defines traits common to a set of related items. This class can then be inherited by other, more specific classes, each adding those things that are unique to it. In the language of C#, a class that is inherited is called a base class. The class that does the inheriting is called the derived class. Therefore a derived class is a specialized version of a base class.

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

E Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Abstraction in C# (and .NET in general) is a fundamental object-oriented programming concept that involves hiding complex implementation details and exposing only the necessary parts of an object. This makes it easier to manage and work with objects by reducing complexity and increasing reusability. In C#, abstraction can be achieved using abstract classes and interfaces. Abstract Classes An abstract class cannot be instantiated directly and may contain abstract methods (methods without a body) that must be implemented by derived classes. It can also include concrete methods (methods with a body ). .  

Interfaces An interface defines a contract that implementing classes must follow. Interfaces cannot contain any implementation, only method, property, event, or indexer declarations . Example : Visual studio( AbstractClassExample ) Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Polymorphism Polymorphism is one of the core principles of object-oriented programming (OOP) and refers to the ability of different classes to be treated as instances of the same class through inheritance. In C#, polymorphism allows you to define methods in a base class and override them in derived classes. There are two types of polymorphism in C#: Compile-time polymorphism (Method Overloading) Run-time polymorphism (Method Overriding) Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Compile-time Polymorphism (Method Overloading) Method overloading occurs when you have multiple methods in the same class with the same name but different parameters. Run-time Polymorphism (Method Overriding) Method overriding occurs when a base class declares a method and a derived class overrides this method with its own implementation. Example: Visual Studio( PolymorphismExample ) Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Encapsulation Encapsulation is one of the four fundamental principles of object-oriented programming (OOP). It refers to the bundling of data (attributes) and methods (functions) that operate on the data into a single unit or class. Key Points of Encapsulation Data Hiding: Internal object details (data members) are hidden from the outside world and only accessible through public methods. Controlled Access: Access to the data is controlled through getters and setters . Example : Visual studio( EncapsulationExample ) Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

E Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Constructors In C#, a constructor is a special method of a class that is automatically called when an instance of the class is created. It is used to initialize the object’s data members. Constructors have the same name as the class and do not have a return type, not even void .

E Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Types of Constructors Default Constructor: Automatically provided by C# if no constructors are defined. Initializes fields to their default values. Parameterized Constructor: Takes parameters to allow different ways of initializing an object. Copy Constructor: Initializes an object using another object of the same class. Static Constructor: Used to initialize static members of the class.

Key Points Default Constructor: No parameters, initializes fields to default values. Parameterized Constructor: Accepts parameters to initialize fields. Copy Constructor: Initializes a new object as a copy of an existing object. Static Constructor: Initializes static members of the class, called once, before any instance is created or any static members are referenced. Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts Function overloading Function overriding(Virtual function) Hiding methods

Function overloading Function overloading allows multiple methods in the same scope to have the same name but different signatures (i.e., different parameter lists ) Example : Function Overloading same as polymorphism Function overriding Function overriding refers to the ability to define a method in a subclass that has the same name and signature as a method in its superclass. When a method is overridden, the subclass's version of the method is called instead of the superclass's version. Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Example : Function Overriding class Animal: def speak(self): print("Some generic animal sound ") class Dog(Animal): def speak(self): print("Woof !") # Example usage animal = Animal() animal.speak () # Output: Some generic animal sound dog = Dog() dog.speak () # Output: Woof! Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Hiding methods H iding methods is often done using the new keyword. This allows a subclass to define a method with the same name as a method in its base class, but the base class's method is hidden rather than overridden. This is different from method overriding, where the base class method is overridden and calls the overridden method in the subclass. Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts

Chapter 2 Introduction to C# 2.2 Object Oriented Concepts
Tags