An example would be a class called Student. Classes possess characteristics in programming they are referred to as properties. An example would be a set of grades. Classes also expose behavior known in programming as methods. An example would be sitting an exam. Methods and properties can be visible only within the scope of the class, which declared them and their descendants private protected, or visible to all other classes public. Objects are instances of classes. For example, John is a Student and Peter is also a Student. Object oriented programming is the successor of procedural structural programming. The Flintstones & WWE: Stone Age Smackdown Cartoon Out. Procedural programming describes programs as groups of reusable code units procedures which define input and output parameters. Procedural programs consist of procedures, which invoke each other. The problem with procedural programming is that code reusability is hard and limited only procedures can be reused and it is hard to make them generic and flexible. There is no easy way to work with abstract data structures with different implementations. The object oriented approach relies on the paradigm that each and every program works with data that describes entities objects or events from real life. For example accounting software systems work with invoices, items, warehouses, availabilities, sale orders, etc. This is how objects came to be. They describe characteristics properties and behavior methods of such real life entities. The main advantages and goals of OOP are to make complex software faster to develop and easier to maintain. OOP enables the easy reuse of code by applying simple and widely accepted rules principles. Lets check them out. In order for a programming language to be object oriented, it has to enable working with classes and objects as well as the implementation and use of the fundamental object oriented principles and concepts inheritance, abstraction, encapsulation and polymorphism. Lets summarize each of these fundamental principles of OOP Encapsulation. We will learn to hide unnecessary details in our classes and provide a clear and simple interface for working with them. Inheritance. We will explain how class hierarchies improve code readability and enable the reuse of functionality. Abstraction. We will learn how to work through abstractions to deal with objects considering their important characteristics and ignore all other details. Polymorphism. We will explain how to work in the same manner with different objects, which define a specific implementation of some abstract behavior. Some OOP theorists also put the concept of exception handling as additional fifth fundamental principle of OOP. We shall not get into a detailed dispute about whether or not exceptions are part of OOP and rather will note that exceptions are supported in all modern object oriented languages and are the primary mechanism of handling errors and unusual situations in object oriented programming. Exceptions always come together with OOP and their importance is explained in details in the chapter Exception Handling. Inheritance. Inheritance is a fundamental principle of object oriented programming. It allows a class to inherit behavior or characteristics of another, more general class. For example, a lion belongs to the biological family of cats Felidae. All cats that have four paws, are predators and hunt their prey. This functionality can be coded once in the Felidae class and all its predators can reuse it Tiger, Puma, Bobcat, etc. Inheritance is described as is kind of relationship, e. Tiger is kind of Animal. How Does Inheritance Work in. NET Inheritance in. NET is defined with a special construct in the class declaration. In. NET and other modern programming languages, a class can inherit from a single class only single inheritance, unlike C which supports inheriting from multiple classes multiple inheritance. This limitation is necessitated by the difficulty in deciding which method to use when there are duplicate methods across classes in C, this problem is solved in a very complicated manner. In. NET, classes can inherit multiple interfaces, which we will discuss later. The class from which we inherit is referred to as parent class or base class super class. Inheritance of Classes Example. Lets take a look at an example of class inheritance in. NET. This is how a base class looks like Felidae. Felidae is latin for catslt summary publicclass. Felidae privatebool male This constructor calls another constructor public Felidae thistrue This is the constructor that is inherited public Felidaebool male this. Male get return male set this. This is how the inheriting class, Lion, looks like Lion. Lion Felidae privateint weight Keyword base will be explained in the next paragraph public Lionbool male, int weight basemale this. Weight get return weight set this. The base Keyword. In the above example, we used the keywordbase in the constructor of the class Lion. The keyword indicates that the base class must be used and allows access to its methods, constructors and member variables. Using base, we can call the constructor of the base class. Using base. Method we can invoke a method of the base class, pass parameters to it and use its results. Using base. field we can get the value of a member variable from the base class or assign a different one to it. In. NET, methods inherited from the base class and declared as virtual can be overridden. This means changing their implementation the original source code from the base class is ignored and new code takes its place. More on overriding methods we will discuss in Virtual Methods. We can invoke non overridden methods from the base class without using the keyword base. Using the keyword is required only if we have an overridden method or variable with the same name in the inheriting class. The keyword base can be used explicitly for clarity. Such source code is easier to read, because we know where to look for the method in question. Bear in mind that using the keyword this is not the same. It can mean accessing a method from the current, as well as the base class. You can take a look at the example in the section about access modifiers and inheritance. There it is clearly explained which members of the base class methods, constructors and member variables are accessible. Constructors with Inheritance. When inheriting a class, our constructors must call the base class constructor, so that it can initialize its member variables. If we do not do this explicitly, the compiler will place a call to the parameterless base class constructor, base, at the beginning of all our inheriting class constructors. Here is an example publicclass. Extending. Class Base. Class public Extending.