This document provides an overview of key concepts in object-oriented programming including inheritance, polymorphism, abstract classes, interfaces, and access modifiers. Inheritance allows a new class to inherit properties and methods from a parent class. Polymorphism allows objects to perform the same action in different ways. Abstract classes and interfaces allow for abstraction by defining methods without implementation. Access modifiers like public and private control the visibility and accessibility of classes, methods, and properties.
This document provides an overview of key concepts in object-oriented programming including inheritance, polymorphism, abstract classes, interfaces, and access modifiers. Inheritance allows a new class to inherit properties and methods from a parent class. Polymorphism allows objects to perform the same action in different ways. Abstract classes and interfaces allow for abstraction by defining methods without implementation. Access modifiers like public and private control the visibility and accessibility of classes, methods, and properties.
This document provides an overview of key concepts in object-oriented programming including inheritance, polymorphism, abstract classes, interfaces, and access modifiers. Inheritance allows a new class to inherit properties and methods from a parent class. Polymorphism allows objects to perform the same action in different ways. Abstract classes and interfaces allow for abstraction by defining methods without implementation. Access modifiers like public and private control the visibility and accessibility of classes, methods, and properties.
Learning Topics: • Inheritance • Writing Parent Class • Writing Child Class • The Main() method • Polymorphism • GetType() and typeof() • Abstract Class and Methods • Interfaces • Access Modifiers and Revisited Inheritance • Inheritance is one of the key concepts of object-oriented programming. Simply stated, inheritance allows us to create a new class from an existing class so that we can effectively reuse existing code. • The class from which a new class is created is known as the base class (parent or superclass). And, the new class is called derived class (child or subclass) • The derived class inherits the fields and methods of the base class. This helps with the code reusability in C#. Inheritance • In C#, we use the : symbol to perform inheritance. For example, Parent Class • Parent class is the class being inherited from, also called base class. Child Class • Child class is the class that inherits from another class, also called derived class. Main() method • The Main method is the entry point of a C# console application or windows application. When the application is started, the Main method is the first method that is invoked. This Main() method is present in every executable application. Executable means any Console application, Windows desktop application or Windows service application. Polymorphism • Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance. • Like we specified in the previous chapter; Inheritance lets us inherit fields and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways. Polymorphism • Polymorphism, in C#, is the ability of objects of different types to provide a unique interface for different implementations of methods. It is usually used in the context of late binding, where the behavior of an object to respond to a call to its method members is determined based on object type at run time. Polymorphism enables redefining methods in derived classes. Polymorphism GetType() and typeof() • GetType() is a method you call on individual objects, to get the execution-time type of the object. • Typeof() is an operator to obtain a type known at compile- time (or at least a generic type parameter). The operand of typeof is always the name of a type or type parameter - never an expression with a value (e.g. a variable). See the C# language specification for more details. Abstract Class and Methods • Data abstraction is the process of hiding certain details and showing only essential information to the user. • Abstraction can be achieved with either abstract classes or interfaces (which you will learn more about in the next chapter). Interfaces • Another way to achieve abstraction in C#, is with interfaces. • An interface is a completely "abstract class", which can only contain abstract methods and properties (with empty bodies): Access Modifiers • The public keyword is an access modifier, which is used to set the access level/visibility for classes, fields, methods and properties. • C# has the following access modifiers: Private Modifier • If you declare a field with a private access modifier, it can only be accessed within the same class: Public Modifier • If you declare a field with a public access modifier, it is accessible for all classes: Thanks for listening! Alubijid | Balubal | Cagayan de Oro | Claveria | Jasaan | Oroquieta | Panaon | Villanueva
Python Projects for Beginners: Part 4. Object-Oriented Programming (OOP). Get an introduction to OOP concepts such as classes, objects, inheritance, and polymorphism