This document discusses object-oriented programming concepts in C++ including inheritance, polymorphism, and abstraction. It begins with definitions of inheritance and how classes derive from base classes. It then provides examples of single, multiple, and multilevel inheritance using the public, private, and protected access specifiers. It also discusses abstract classes, virtual functions, and the role of constructors in inheritance. The document is a lecture on OOP concepts in C++ presented to students.
- Inheritance is a mechanism where a derived class inherits properties from a base class. The derived class can have additional properties as well.
- The base class is called the parent/super class and the derived class is called the child/sub class. The subclass inherits all non-private fields and methods from the parent class.
- Key benefits of inheritance include code reusability, extensibility, data hiding and method overriding. Inheritance promotes software reuse by allowing subclasses to reuse code from the parent class.
Inheritance allows a subclass to inherit properties and methods from a superclass. There are several types of inheritance in Java including single, multilevel, hierarchical, and hybrid inheritance. Single inheritance involves a subclass extending one superclass. Multilevel inheritance allows a subclass to inherit from another subclass. Hierarchical inheritance has one superclass with multiple subclasses. Hybrid inheritance combines single and multiple inheritance by implementing interfaces.
Inheritance allows classes to derive from existing classes, promoting code reuse. There are different types of inheritance like single, multilevel, multiple, and hierarchical. Constructors and destructors are called in the reverse order in inheritance, with base class constructors called before derived class constructors, and base class destructors called after derived class destructors.
The document discusses the concept of constructors in Java. It defines a constructor as a special method that initializes an object immediately upon creation and has the same name as the class. The document explains different types of constructors - default, explicit, parameterized, and overloaded constructors. It provides examples to illustrate these constructor types and how they are used to initialize object properties. The key differences between methods and constructors are also outlined.
This document discusses the diamond problem that can occur with multiple inheritance in C++. Specifically, it shows an example where a class "four" inherits from classes "two" and "three", which both inherit from class "one". This results in two copies of the base class "one" being present in objects of class "four", leading to ambiguity when trying to access attributes from the base class. The document presents two ways to resolve this issue: 1) manual selection using scope resolution to specify which attribute to access, and 2) making the inheritance of the base class "one" virtual in classes "two" and "three", which ensures only one copy of the base class exists in class "four" objects. The virtual
This document describes the design of an object-oriented programming language. It discusses:
1) The basic structure of programs as blocks of expressions that enrich the environment. Classes, objects, and procedures are all treated as values.
2) The abstract syntax for expressions including class and object creation, field and method declaration, inheritance, and cloning.
3) How values are represented, including objects, entries for fields/methods, and procedures. Inheritance is implemented by copying fields and methods.
4) Data structures like objects and entries that represent values. Inheritance works by finding fields/methods in superclasses and copying them.
The aptitude test consisted tricky questions on core subjects of CSE like C , C++, Java ,Data Structures, Database, Computer Networks, Theory of Computation.
- Inheritance is a mechanism where a derived class inherits properties from a base class. The derived class can have additional properties as well.
- The base class is called the parent/super class and the derived class is called the child/sub class. The subclass inherits all non-private fields and methods from the parent class.
- Key benefits of inheritance include code reusability, extensibility, data hiding and method overriding. Inheritance promotes software reuse by allowing subclasses to reuse code from the parent class.
Inheritance allows a subclass to inherit properties and methods from a superclass. There are several types of inheritance in Java including single, multilevel, hierarchical, and hybrid inheritance. Single inheritance involves a subclass extending one superclass. Multilevel inheritance allows a subclass to inherit from another subclass. Hierarchical inheritance has one superclass with multiple subclasses. Hybrid inheritance combines single and multiple inheritance by implementing interfaces.
Inheritance allows classes to derive from existing classes, promoting code reuse. There are different types of inheritance like single, multilevel, multiple, and hierarchical. Constructors and destructors are called in the reverse order in inheritance, with base class constructors called before derived class constructors, and base class destructors called after derived class destructors.
The document discusses the concept of constructors in Java. It defines a constructor as a special method that initializes an object immediately upon creation and has the same name as the class. The document explains different types of constructors - default, explicit, parameterized, and overloaded constructors. It provides examples to illustrate these constructor types and how they are used to initialize object properties. The key differences between methods and constructors are also outlined.
This document discusses the diamond problem that can occur with multiple inheritance in C++. Specifically, it shows an example where a class "four" inherits from classes "two" and "three", which both inherit from class "one". This results in two copies of the base class "one" being present in objects of class "four", leading to ambiguity when trying to access attributes from the base class. The document presents two ways to resolve this issue: 1) manual selection using scope resolution to specify which attribute to access, and 2) making the inheritance of the base class "one" virtual in classes "two" and "three", which ensures only one copy of the base class exists in class "four" objects. The virtual
This document describes the design of an object-oriented programming language. It discusses:
1) The basic structure of programs as blocks of expressions that enrich the environment. Classes, objects, and procedures are all treated as values.
2) The abstract syntax for expressions including class and object creation, field and method declaration, inheritance, and cloning.
3) How values are represented, including objects, entries for fields/methods, and procedures. Inheritance is implemented by copying fields and methods.
4) Data structures like objects and entries that represent values. Inheritance works by finding fields/methods in superclasses and copying them.
The aptitude test consisted tricky questions on core subjects of CSE like C , C++, Java ,Data Structures, Database, Computer Networks, Theory of Computation.
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Yandex
This document discusses cross-platform development for the iPhone. It outlines two main approaches: porting existing code and writing new code designed for cross-platform use. Porting involves overcoming challenges like incompatible languages and system APIs across platforms. Solutions proposed include runtime libraries like qobjc and frameworks like dCocoa that emulate Objective-C and provide portable APIs. Writing new code allows using languages and libraries like C++, Lua and Qt that are inherently cross-platform. The document provides examples of porting Objective-C code to dCocoa and discusses benefits of a cross-platform approach.
This document discusses implementing multiple inheritance in C++. It begins with an example where a Terminal class needs to inherit from both a Task and Displayed class. It then provides background on multiple inheritance and how it allows combining independent concepts. The document outlines C++'s existing single inheritance implementation strategy before describing the author's approach to multiple inheritance, which preserves C++'s efficiency while supporting an object having more than one base class.
C# is similar to C++ but easier to use, as it does not support pointers, multiple inheritance, header files or global variables. Everything must live within a class or struct. The basic syntax will be familiar to C++ programmers. Key features include properties, interfaces, foreach loops, and delegates for event handling. Properties allow custom getter and setter logic and are preferred over public fields. Delegates provide a type-safe way to link methods, and events build on this to prevent issues with multicast delegates. Generics and assemblies are analogous to C++ templates and deployment units.
The document provides an overview of C++ polymorphism. Some key points include:
1. Polymorphism allows calling the same method for different types through dynamic binding using virtual functions.
2. Virtual functions in a base class can be overridden in derived classes to change behavior at runtime depending on the object type.
3. Pure virtual functions require derived classes to implement them, making a class abstract. Abstract base classes are useful for defining interfaces.
4. Public inheritance models an "is-a" relationship and allows polymorphism, while private inheritance is mainly for encapsulation.
C++ hybrid inheritance allows a class to inherit from multiple classes using more than one form of inheritance. This can cause ambiguity if two base classes define a method with the same name. Ambiguity can be resolved by using the class resolution operator (::) to explicitly call the desired method from the specific base class. The example shows a class D inheriting publicly from both classes B and C, which inherit from classes A and C respectively. Class D is then able to access methods from all base classes.
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
The document discusses object-oriented programming concepts like inheritance, encapsulation, polymorphism and data hiding. It provides examples to explain inheritance, where a derived class inherits attributes and behaviors from a base class. Derived classes can specialize or extend the base class while reusing its code.
This document contains an object oriented programming exam with questions about C++ and Java. It includes true/false and multiple choice questions testing knowledge of templates, inheritance, interfaces, exceptions, and other OOP concepts. It also includes coding questions asking to summarize and fix code snippets involving arrays, exceptions, copying objects, and demonstrating virtual functions.
In this session you will learn:
Deep dive into coding OOP with Java… with practical examples.
How to create a class
How to create objects
How to create instance variables
How to create class variables
Constructors
For more information: https://www.mindsmapped.com/courses/software-development/become-a-java-developer-hands-on-training/
The document discusses inheritance in object-oriented programming using C++. It defines inheritance as a capability of one class to inherit properties from another class, with the class inheriting properties called the derived class and the class being inherited from called the base class. It describes single inheritance, multilevel inheritance, and different visibility modes (public, private, protected) that determine how members of the base class are accessible in the derived class. It provides examples of inheritance code in C++ to illustrate these concepts.
Inheritance, Polymorphism, and Virtual Functions allows code reuse through inheritance. It establishes a hierarchical relationship between classes where a derived class inherits attributes and behaviors from its base class. Constructors and destructors of base classes are automatically called when objects of derived classes are created or destroyed. Derived classes can pass arguments to base class constructors and multiple inheritance determines the order of constructor calls. Object composition allows classes to contain instances of other classes to reuse their functionality.
Inheritance, pointers, virtual functions, and polymorphism are essential concepts in object-oriented programming. Here's a brief explanation of each:
Inheritance:
Inheritance is a mechanism in object-oriented programming that allows a new class (a derived or child class) to inherit properties and behaviors from an existing class (a base or parent class).
It promotes code reuse and hierarchy in class relationships.
The derived class can extend or override the inherited attributes and methods, making it more specialized while retaining the common characteristics from the base class.
Pointers:
Pointers are variables that store memory addresses, allowing you to work with memory and objects more efficiently.
In object-oriented programming, pointers are often used to reference objects, enabling dynamic allocation of objects and polymorphism.
Pointers are critical for dynamic memory management and creating data structures like linked lists and trees.
Virtual Functions:
Virtual functions are functions defined in a base class and marked with the virtual keyword.
They enable late binding or runtime polymorphism, allowing derived classes to provide their own implementation of the virtual function.
Virtual functions are crucial for achieving polymorphism and are used in conjunction with pointers to objects.
Polymorphism:
Polymorphism is the ability of objects of different classes to respond to the same method or function call in a way that is specific to their individual types.
There are two types of polymorphism: compile-time polymorphism (function overloading) and runtime polymorphism (achieved through virtual functions).
Polymorphism simplifies code and enables you to work with objects at a higher level of abstraction, using a common interface.
In summary, inheritance allows classes to inherit properties and behaviors from other classes, pointers are used to reference objects and manage memory, virtual functions enable runtime polymorphism, and polymorphism allows objects of different types to be treated as instances of a common base class. These concepts are fundamental to designing flexible and extensible object-oriented software.
This document summarizes key concepts in object-oriented programming (OOP) in Java, including static keyword, instance member, class member, inheritance, encapsulation, polymorphism, object, class, constructor, and more. It provides examples to illustrate static variables and methods, the this keyword, super keyword, final keyword, abstract classes vs interfaces, and method overloading as a form of compile-time polymorphism.
This document discusses inheritance and related object-oriented programming concepts in C#, including:
- Inheritance allows a derived class to inherit attributes from a base class.
- Relationships between classes include inheritance, composition, utilization, and instantiation.
- Abstract classes cannot be instantiated but provide partial implementation for derived classes to complete. Abstract methods have no body and must be overridden in derived classes.
- Sealed classes cannot be inherited from, while sealed methods cannot be overridden in derived classes.
- Interfaces declare method signatures that classes implement, allowing multiple interface implementation.
oops(object oriented programing ) is introduced in c++ to enhance the 'c' programming. oops concept includes many important concepts like class,objects,abstraction,encapsulation,inheritance etc.
The document provides an overview of C++ vs C# by Shubhra Chauhan. It discusses the key object-oriented programming concepts like classes, objects, inheritance, polymorphism, and how they are implemented in C++ and C#. It includes code examples to demonstrate class usage and inheritance in both languages. The document also compares some similarities and differences between C++ and C# like support for pointers, preprocessors, structures, and goto statements.
This document provides class notes on object-oriented programming concepts like inheritance, packages, and interfaces. It covers topics like method overloading, objects as parameters, returning objects, static and nested classes, inheritance basics, method overriding, abstract classes, packages, and interfaces. The document is organized into sections on each topic with examples provided. It also includes indexes listing the topics covered and their importance levels. The material is intended to complement personalized learning materials and assessment tests for students.
This document discusses inheritance in C++. It defines inheritance as a process where new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and can add new specific features. Inheritance allows for code reusability and saves time by reusing features of the base class. The document then provides examples of single inheritance with a base class and derived class, and examples of different types of inheritance like multilevel, multiple, hierarchical, and hybrid inheritance.
This document provides an agenda and overview of key concepts in object-oriented programming with Java, including:
- Class syntax such as access modifiers, static members, and the 'this' keyword.
- Constructors, initializers, and how to call other constructors.
- Inheritance concepts like subclasses, superclasses, and using the 'super' keyword.
- Interfaces as contracts that can be implemented by classes.
- Nested classes, both static and inner classes, as well as anonymous classes.
- Enums for defining constant sets that can implement methods.
The document provides examples to illustrate each concept.
The document provides an agenda and overview of key concepts in object-oriented programming with Java including:
1. Class syntax such as access modifiers, static members, constructors, initializers, and the 'this' keyword.
2. Inheritance concepts like subclasses, superclasses, overriding methods, and the 'super' keyword.
3. Interfaces as contracts that can be implemented by classes to define common behaviors without implementation.
4. Nested classes including static nested classes and inner classes, as well as anonymous classes defined without a class name.
5. Enums, constructors, and initializers are also covered but examples are not shown.
Inheritance allows classes to inherit properties from other classes. There are several types of inheritance including single, multiple, multilevel, hierarchical, and hybrid inheritance. Inheritance provides advantages like reducing memory usage and development time by allowing classes to reuse functionality from base classes. Access control and constructors also play an important role in inheritance. Virtual base classes are used to avoid multiple copies of base class members in derived classes during hybrid inheritance. Abstract classes provide a framework for other classes to inherit from but cannot be instantiated themselves.
Разработка кросс-платформенного кода между iPhone < -> Windows с помощью o...Yandex
This document discusses cross-platform development for the iPhone. It outlines two main approaches: porting existing code and writing new code designed for cross-platform use. Porting involves overcoming challenges like incompatible languages and system APIs across platforms. Solutions proposed include runtime libraries like qobjc and frameworks like dCocoa that emulate Objective-C and provide portable APIs. Writing new code allows using languages and libraries like C++, Lua and Qt that are inherently cross-platform. The document provides examples of porting Objective-C code to dCocoa and discusses benefits of a cross-platform approach.
This document discusses implementing multiple inheritance in C++. It begins with an example where a Terminal class needs to inherit from both a Task and Displayed class. It then provides background on multiple inheritance and how it allows combining independent concepts. The document outlines C++'s existing single inheritance implementation strategy before describing the author's approach to multiple inheritance, which preserves C++'s efficiency while supporting an object having more than one base class.
C# is similar to C++ but easier to use, as it does not support pointers, multiple inheritance, header files or global variables. Everything must live within a class or struct. The basic syntax will be familiar to C++ programmers. Key features include properties, interfaces, foreach loops, and delegates for event handling. Properties allow custom getter and setter logic and are preferred over public fields. Delegates provide a type-safe way to link methods, and events build on this to prevent issues with multicast delegates. Generics and assemblies are analogous to C++ templates and deployment units.
The document provides an overview of C++ polymorphism. Some key points include:
1. Polymorphism allows calling the same method for different types through dynamic binding using virtual functions.
2. Virtual functions in a base class can be overridden in derived classes to change behavior at runtime depending on the object type.
3. Pure virtual functions require derived classes to implement them, making a class abstract. Abstract base classes are useful for defining interfaces.
4. Public inheritance models an "is-a" relationship and allows polymorphism, while private inheritance is mainly for encapsulation.
C++ hybrid inheritance allows a class to inherit from multiple classes using more than one form of inheritance. This can cause ambiguity if two base classes define a method with the same name. Ambiguity can be resolved by using the class resolution operator (::) to explicitly call the desired method from the specific base class. The example shows a class D inheriting publicly from both classes B and C, which inherit from classes A and C respectively. Class D is then able to access methods from all base classes.
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
The document discusses object-oriented programming concepts like inheritance, encapsulation, polymorphism and data hiding. It provides examples to explain inheritance, where a derived class inherits attributes and behaviors from a base class. Derived classes can specialize or extend the base class while reusing its code.
This document contains an object oriented programming exam with questions about C++ and Java. It includes true/false and multiple choice questions testing knowledge of templates, inheritance, interfaces, exceptions, and other OOP concepts. It also includes coding questions asking to summarize and fix code snippets involving arrays, exceptions, copying objects, and demonstrating virtual functions.
In this session you will learn:
Deep dive into coding OOP with Java… with practical examples.
How to create a class
How to create objects
How to create instance variables
How to create class variables
Constructors
For more information: https://www.mindsmapped.com/courses/software-development/become-a-java-developer-hands-on-training/
The document discusses inheritance in object-oriented programming using C++. It defines inheritance as a capability of one class to inherit properties from another class, with the class inheriting properties called the derived class and the class being inherited from called the base class. It describes single inheritance, multilevel inheritance, and different visibility modes (public, private, protected) that determine how members of the base class are accessible in the derived class. It provides examples of inheritance code in C++ to illustrate these concepts.
Inheritance, Polymorphism, and Virtual Functions allows code reuse through inheritance. It establishes a hierarchical relationship between classes where a derived class inherits attributes and behaviors from its base class. Constructors and destructors of base classes are automatically called when objects of derived classes are created or destroyed. Derived classes can pass arguments to base class constructors and multiple inheritance determines the order of constructor calls. Object composition allows classes to contain instances of other classes to reuse their functionality.
Inheritance, pointers, virtual functions, and polymorphism are essential concepts in object-oriented programming. Here's a brief explanation of each:
Inheritance:
Inheritance is a mechanism in object-oriented programming that allows a new class (a derived or child class) to inherit properties and behaviors from an existing class (a base or parent class).
It promotes code reuse and hierarchy in class relationships.
The derived class can extend or override the inherited attributes and methods, making it more specialized while retaining the common characteristics from the base class.
Pointers:
Pointers are variables that store memory addresses, allowing you to work with memory and objects more efficiently.
In object-oriented programming, pointers are often used to reference objects, enabling dynamic allocation of objects and polymorphism.
Pointers are critical for dynamic memory management and creating data structures like linked lists and trees.
Virtual Functions:
Virtual functions are functions defined in a base class and marked with the virtual keyword.
They enable late binding or runtime polymorphism, allowing derived classes to provide their own implementation of the virtual function.
Virtual functions are crucial for achieving polymorphism and are used in conjunction with pointers to objects.
Polymorphism:
Polymorphism is the ability of objects of different classes to respond to the same method or function call in a way that is specific to their individual types.
There are two types of polymorphism: compile-time polymorphism (function overloading) and runtime polymorphism (achieved through virtual functions).
Polymorphism simplifies code and enables you to work with objects at a higher level of abstraction, using a common interface.
In summary, inheritance allows classes to inherit properties and behaviors from other classes, pointers are used to reference objects and manage memory, virtual functions enable runtime polymorphism, and polymorphism allows objects of different types to be treated as instances of a common base class. These concepts are fundamental to designing flexible and extensible object-oriented software.
This document summarizes key concepts in object-oriented programming (OOP) in Java, including static keyword, instance member, class member, inheritance, encapsulation, polymorphism, object, class, constructor, and more. It provides examples to illustrate static variables and methods, the this keyword, super keyword, final keyword, abstract classes vs interfaces, and method overloading as a form of compile-time polymorphism.
This document discusses inheritance and related object-oriented programming concepts in C#, including:
- Inheritance allows a derived class to inherit attributes from a base class.
- Relationships between classes include inheritance, composition, utilization, and instantiation.
- Abstract classes cannot be instantiated but provide partial implementation for derived classes to complete. Abstract methods have no body and must be overridden in derived classes.
- Sealed classes cannot be inherited from, while sealed methods cannot be overridden in derived classes.
- Interfaces declare method signatures that classes implement, allowing multiple interface implementation.
oops(object oriented programing ) is introduced in c++ to enhance the 'c' programming. oops concept includes many important concepts like class,objects,abstraction,encapsulation,inheritance etc.
The document provides an overview of C++ vs C# by Shubhra Chauhan. It discusses the key object-oriented programming concepts like classes, objects, inheritance, polymorphism, and how they are implemented in C++ and C#. It includes code examples to demonstrate class usage and inheritance in both languages. The document also compares some similarities and differences between C++ and C# like support for pointers, preprocessors, structures, and goto statements.
This document provides class notes on object-oriented programming concepts like inheritance, packages, and interfaces. It covers topics like method overloading, objects as parameters, returning objects, static and nested classes, inheritance basics, method overriding, abstract classes, packages, and interfaces. The document is organized into sections on each topic with examples provided. It also includes indexes listing the topics covered and their importance levels. The material is intended to complement personalized learning materials and assessment tests for students.
This document discusses inheritance in C++. It defines inheritance as a process where new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and can add new specific features. Inheritance allows for code reusability and saves time by reusing features of the base class. The document then provides examples of single inheritance with a base class and derived class, and examples of different types of inheritance like multilevel, multiple, hierarchical, and hybrid inheritance.
This document provides an agenda and overview of key concepts in object-oriented programming with Java, including:
- Class syntax such as access modifiers, static members, and the 'this' keyword.
- Constructors, initializers, and how to call other constructors.
- Inheritance concepts like subclasses, superclasses, and using the 'super' keyword.
- Interfaces as contracts that can be implemented by classes.
- Nested classes, both static and inner classes, as well as anonymous classes.
- Enums for defining constant sets that can implement methods.
The document provides examples to illustrate each concept.
The document provides an agenda and overview of key concepts in object-oriented programming with Java including:
1. Class syntax such as access modifiers, static members, constructors, initializers, and the 'this' keyword.
2. Inheritance concepts like subclasses, superclasses, overriding methods, and the 'super' keyword.
3. Interfaces as contracts that can be implemented by classes to define common behaviors without implementation.
4. Nested classes including static nested classes and inner classes, as well as anonymous classes defined without a class name.
5. Enums, constructors, and initializers are also covered but examples are not shown.
Inheritance allows classes to inherit properties from other classes. There are several types of inheritance including single, multiple, multilevel, hierarchical, and hybrid inheritance. Inheritance provides advantages like reducing memory usage and development time by allowing classes to reuse functionality from base classes. Access control and constructors also play an important role in inheritance. Virtual base classes are used to avoid multiple copies of base class members in derived classes during hybrid inheritance. Abstract classes provide a framework for other classes to inherit from but cannot be instantiated themselves.
Inheritance allows the creation of new classes from existing classes. There are different types of inheritance including single, multiple, multilevel, hierarchical and hybrid. Multilevel inheritance allows a derived class to inherit from another derived class. Constructors and destructors are called from base to derived classes. Multiple inheritance requires derived classes to pass arguments to multiple base class constructors.
This document discusses multiple inheritance in object-oriented programming. Multiple inheritance allows a child class to inherit properties and methods from multiple parent classes. It describes key concepts like parent class, child class, and the syntax for declaring a class with multiple inheritance. The document also discusses potential issues like constructor calling order and resolving ambiguity when the same method is defined in both parent classes.
The document discusses object oriented programming concepts like class, object, encapsulation, inheritance and polymorphism. It provides examples of defining a class with data members and member functions in C++. It also explains constructors, destructors, different types of constructors like default, parameterized and copy constructor. Examples are given to illustrate how objects are created from a class and how member functions can be defined internally or externally.
The document discusses different types of inheritance in object-oriented programming, including single, multi-level, multiple, hierarchical, and hybrid inheritance. Single inheritance involves deriving a subclass from one superclass. Multi-level inheritance allows a derived class to be further derived by another class. Multiple inheritance allows a class to inherit from more than one parent class. Hierarchical inheritance involves deriving multiple classes from a single base class. Hybrid inheritance uses multiple and multi-level inheritance techniques together to derive a new subclass. Examples are provided to illustrate each type of inheritance.
Classes and Objects
Classes in C++
Declaring Objects
Access Specifiers and their Scope
Defining Member Function
Overloading Member Function
Nested class
Constructors and Destructors
Introduction
Characteristics of Constructor and Destructor
Application with Constructor
Constructor with Arguments (parameterized Constructors)
Destructors
C++ inheritance allows one class to inherit attributes and behaviors from another class. The class that inherits is called the derived class, while the class being inherited from is called the base class. Inheritance promotes code reuse and helps with program design. The key advantages are that derived classes can reuse code from the base class without redefining members, and class libraries can be easily built and distributed by deriving new classes from existing ones. C++ supports various types of inheritance including single, multiple, hierarchical and multilevel inheritance.
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...PriyankaKilaniya
Energy efficiency has been important since the latter part of the last century. The main object of this survey is to determine the energy efficiency knowledge among consumers. Two separate districts in Bangladesh are selected to conduct the survey on households and showrooms about the energy and seller also. The survey uses the data to find some regression equations from which it is easy to predict energy efficiency knowledge. The data is analyzed and calculated based on five important criteria. The initial target was to find some factors that help predict a person's energy efficiency knowledge. From the survey, it is found that the energy efficiency awareness among the people of our country is very low. Relationships between household energy use behaviors are estimated using a unique dataset of about 40 households and 20 showrooms in Bangladesh's Chapainawabganj and Bagerhat districts. Knowledge of energy consumption and energy efficiency technology options is found to be associated with household use of energy conservation practices. Household characteristics also influence household energy use behavior. Younger household cohorts are more likely to adopt energy-efficient technologies and energy conservation practices and place primary importance on energy saving for environmental reasons. Education also influences attitudes toward energy conservation in Bangladesh. Low-education households indicate they primarily save electricity for the environment while high-education households indicate they are motivated by environmental concerns.
Generative AI Use cases applications solutions and implementation.pdfmahaffeycheryld
Generative AI solutions encompass a range of capabilities from content creation to complex problem-solving across industries. Implementing generative AI involves identifying specific business needs, developing tailored AI models using techniques like GANs and VAEs, and integrating these models into existing workflows. Data quality and continuous model refinement are crucial for effective implementation. Businesses must also consider ethical implications and ensure transparency in AI decision-making. Generative AI's implementation aims to enhance efficiency, creativity, and innovation by leveraging autonomous generation and sophisticated learning algorithms to meet diverse business challenges.
https://www.leewayhertz.com/generative-ai-use-cases-and-applications/
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Sinan KOZAK
Sinan from the Delivery Hero mobile infrastructure engineering team shares a deep dive into performance acceleration with Gradle build cache optimizations. Sinan shares their journey into solving complex build-cache problems that affect Gradle builds. By understanding the challenges and solutions found in our journey, we aim to demonstrate the possibilities for faster builds. The case study reveals how overlapping outputs and cache misconfigurations led to significant increases in build times, especially as the project scaled up with numerous modules using Paparazzi tests. The journey from diagnosing to defeating cache issues offers invaluable lessons on maintaining cache integrity without sacrificing functionality.
Rainfall intensity duration frequency curve statistical analysis and modeling...bijceesjournal
Using data from 41 years in Patna’ India’ the study’s goal is to analyze the trends of how often it rains on a weekly, seasonal, and annual basis (1981−2020). First, utilizing the intensity-duration-frequency (IDF) curve and the relationship by statistically analyzing rainfall’ the historical rainfall data set for Patna’ India’ during a 41 year period (1981−2020), was evaluated for its quality. Changes in the hydrologic cycle as a result of increased greenhouse gas emissions are expected to induce variations in the intensity, length, and frequency of precipitation events. One strategy to lessen vulnerability is to quantify probable changes and adapt to them. Techniques such as log-normal, normal, and Gumbel are used (EV-I). Distributions were created with durations of 1, 2, 3, 6, and 24 h and return times of 2, 5, 10, 25, and 100 years. There were also mathematical correlations discovered between rainfall and recurrence interval.
Findings: Based on findings, the Gumbel approach produced the highest intensity values, whereas the other approaches produced values that were close to each other. The data indicates that 461.9 mm of rain fell during the monsoon season’s 301st week. However, it was found that the 29th week had the greatest average rainfall, 92.6 mm. With 952.6 mm on average, the monsoon season saw the highest rainfall. Calculations revealed that the yearly rainfall averaged 1171.1 mm. Using Weibull’s method, the study was subsequently expanded to examine rainfall distribution at different recurrence intervals of 2, 5, 10, and 25 years. Rainfall and recurrence interval mathematical correlations were also developed. Further regression analysis revealed that short wave irrigation, wind direction, wind speed, pressure, relative humidity, and temperature all had a substantial influence on rainfall.
Originality and value: The results of the rainfall IDF curves can provide useful information to policymakers in making appropriate decisions in managing and minimizing floods in the study area.
Introduction- e - waste – definition - sources of e-waste– hazardous substances in e-waste - effects of e-waste on environment and human health- need for e-waste management– e-waste handling rules - waste minimization techniques for managing e-waste – recycling of e-waste - disposal treatment methods of e- waste – mechanism of extraction of precious metal from leaching solution-global Scenario of E-waste – E-waste in India- case studies.
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...shadow0702a
This document serves as a comprehensive step-by-step guide on how to effectively use PyCharm for remote debugging of the Windows Subsystem for Linux (WSL) on a local Windows machine. It meticulously outlines several critical steps in the process, starting with the crucial task of enabling permissions, followed by the installation and configuration of WSL.
The guide then proceeds to explain how to set up the SSH service within the WSL environment, an integral part of the process. Alongside this, it also provides detailed instructions on how to modify the inbound rules of the Windows firewall to facilitate the process, ensuring that there are no connectivity issues that could potentially hinder the debugging process.
The document further emphasizes on the importance of checking the connection between the Windows and WSL environments, providing instructions on how to ensure that the connection is optimal and ready for remote debugging.
It also offers an in-depth guide on how to configure the WSL interpreter and files within the PyCharm environment. This is essential for ensuring that the debugging process is set up correctly and that the program can be run effectively within the WSL terminal.
Additionally, the document provides guidance on how to set up breakpoints for debugging, a fundamental aspect of the debugging process which allows the developer to stop the execution of their code at certain points and inspect their program at those stages.
Finally, the document concludes by providing a link to a reference blog. This blog offers additional information and guidance on configuring the remote Python interpreter in PyCharm, providing the reader with a well-rounded understanding of the process.
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...IJECEIAES
Climate change's impact on the planet forced the United Nations and governments to promote green energies and electric transportation. The deployments of photovoltaic (PV) and electric vehicle (EV) systems gained stronger momentum due to their numerous advantages over fossil fuel types. The advantages go beyond sustainability to reach financial support and stability. The work in this paper introduces the hybrid system between PV and EV to support industrial and commercial plants. This paper covers the theoretical framework of the proposed hybrid system including the required equation to complete the cost analysis when PV and EV are present. In addition, the proposed design diagram which sets the priorities and requirements of the system is presented. The proposed approach allows setup to advance their power stability, especially during power outages. The presented information supports researchers and plant owners to complete the necessary analysis while promoting the deployment of clean energy. The result of a case study that represents a dairy milk farmer supports the theoretical works and highlights its advanced benefits to existing plants. The short return on investment of the proposed approach supports the paper's novelty approach for the sustainable electrical system. In addition, the proposed system allows for an isolated power setup without the need for a transmission line which enhances the safety of the electrical network
Discover the latest insights on Data Driven Maintenance with our comprehensive webinar presentation. Learn about traditional maintenance challenges, the right approach to utilizing data, and the benefits of adopting a Data Driven Maintenance strategy. Explore real-world examples, industry best practices, and innovative solutions like FMECA and the D3M model. This presentation, led by expert Jules Oudmans, is essential for asset owners looking to optimize their maintenance processes and leverage digital technologies for improved efficiency and performance. Download now to stay ahead in the evolving maintenance landscape.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Inheritance
1. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
OOPS Using C++ 1
OOPS Using C++ 1
1
Object Oriented Programming
Using C++
Subject Teacher:-
Dr. Shiraz Khurana
2. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
2
What is Inheritance ?
■ Reusability.
■ Is the process by which new class (or
classes are created from existing class (or
classes).
■ Derived classes have all the features of
the base class in addition to some new
features.
■ The new inheriting class is called derived
or sub class and inherited class is called
base or super class.
OOPS Using C++
3. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
3
How to inherit a class?
1. Define a base class of which all properties are to
be inherited.
2. Define a derived class as
class derived_cls_name : access-specifier
base_cls_name
{ BODY OF THE DERIVED CLASS } ;
3. Access specifier can be either public , protected
or private (if nothing is specified then default
access-specifier is private)
Access specifier also called visibility mode which
specifies whether the features of the base class
are privately or publicly derived.
OOPS Using C++
4. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
4
■ If access specifier is public
1. All public members of the base class
become public members of derived class.
2. All protected members of base class
become protected members of derived
class.
3. Private members of base class are still
private to base class ,thus not accessible to
derived class.
OOPS Using C++
5. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
5
Inheritance using public access specifier
#include"iostream.h"
#include<string.h>
class student
{ int rollno; char name[12];
public:
void get_details()
{ cout<<"enter roll no and name";
cin>>rollno>>name; }
void display()
{ cout<<"roll no is "<<rollno<<"and name is
"<<name;} }; // Base class ends here
OOPS Using C++
6. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
6
class cse_student :public student
{
char sub1[10],sub2[10];
public:
cse_student( ) // CONSTRUCTOR
{ strcpy(sub1,"OOPS");
strcpy(sub2,"PROGRAMMING");}
void sub_display()
{ cout<<"and subjects
are"<<sub1<<"and"<<sub2;
} };
OOPS Using C++
7. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
7
int main (void)
{
cse_student c1;
c1.get_details();
c1.display();
c1.sub_display();
return 0;
}
Public members of base class
are accessed as public of
derived
OOPS Using C++
8. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
8
Output
■ enter roll no and name 12 ABC
■ roll no is 12
■ and name is ABC
■ and subjects are OOPS and
PROGRAMMING
OOPS Using C++
9. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
9
■ If access specifier is private then
1. All public and protected members of base
class become private members of derived
class.
2. Private members of base class remain as
private to it and hence not accessible to
derived class.
3. All public and protected members of a class
can be accessed by its own objects using
the dot operator.
4. No member of base class is accessible to
the objects of the derived class.
OOPS Using C++
10. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
10
Inheritance using private access specifier
#include"iostream.h"
#include<string.h>
class student
{
int rollno; char name[12];
public:
void get_details()
{ cout<<"enter roll no and name";
cin>>rollno>>name;}
void display()
{ cout<<"roll no is "<<rollno<<"and name is"<<name;}
};
OOPS Using C++
11. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
11
class cse_student :private student
{
char sub1[10],sub2[10];
public:
cse_student() // CONSTRUCTOR
{ strcpy(sub1,"OOPS");
strcpy(sub2,"PROGRAMMING");
get_details();
}
void sub_display()
{ display();
// cout<<"rollno is "<<rollno; // Rollno not accessible
cout<<"and subjects are"<<sub1<<"and"<<sub2;}
};
Now private member of
cse_student
OOPS Using C++
12. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
12
int main (void)
{
cse_student c1;
//c1.get_details(); private member of
//c1.display(); base class in-accessible
c1.sub_display();
return 0;
}
OOPS Using C++
13. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
13
Output
enter roll no and name
12
neeraj
roll no is 12 and name is neeraj
and subjects are OOPS and PROGRAMMING
OOPS Using C++
14. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
14
“Protected” Access Specifier
■ A protected member of a class behaves
similar to private members ( that is
accessible only to members of the class)
BUT
■ If the class is inherited by some class then
protected members of base class may be
accessible to derived class (different from
PRIVATE MEMBERS OF BASE CLASS)
■ Thus protected members of a class are despite
being private to it can be inherited by some other
class.
OOPS Using C++
15. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
15
#include"iostream.h"
class student
{
protected:
int rollno; char name[12];
void get_details()
{ cout<<"enter roll no and name";
cin>>rollno>>name;}
public:
student()
{ get_details(); }
void display()
{ cout<<endl<<"roll no is "<<rollno<<"and name is
"<<name<<endl; } };
OOPS Using C++
16. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
16
class it_student :public student
{
char sub1[10],sub2[10];
public:
it_student()
{
strcpy(sub1,"OOPS");
strcpy(sub2,"PROGRAMMING");
get_details(); // valid as get_details is PROTECTED and
not PRIVATE
}
void display1()
{
cout<<"rollno and name are"<<rollno<<"t"<<name;
cout<<endl<<"and subjects are"<<sub1<<"and"<<sub2;
}};
OOPS Using C++
17. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
17
int main (void)
{
student s;
//s.get_details(); // get_details is private to student
s.display(); // valid being PUBLIC to student
it_student c1;
//c1.get_details(); //get_details is private to it_student
c1.display(); //valid ,display() is public to
//it_student
c1.display1();
return 0;
}
OOPS Using C++
18. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
18
Output
■ enter roll no and name123 angel
■ roll no is 123and name is angel
■ enter roll no and name45 angel2
■ rollno and name are45 angel2
and subjects are OOPS and
PROGRAMMING
OOPS Using C++
19. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
19
Inheriting a class in protected mode
■ Both public and protected members of base
class become protected members of derived
class.
■ Private members of base class remain
private to it and hence in-accessible to
derived class.
OOPS Using C++
20. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
20
Visibility of inherited members
Base class
visibility
Derived class visibilty
Public
derivation
Private
derivation
Protected
Derivation
Private Not
inherited
Not
Inherited
Not
Inherited
Protected Protected Private Protected
Public Public Private Protected
OOPS Using C++
21. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
Forms Of Inheritance
(a) Single Inheritance
(b) Multiple Inheritance
(c) Hierarchical Inheritance
(d) Multilevel Inheritance
(e) Hybrid Inheritance
OOPS Using C++ 21
22. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
22
More on inheritance….
Derived class may inherit traits from more
than one class ( multiple inheritance)
Class Z: access_specifier X, access_specifier
Y...
Y
X
Z
Multiple Inheritance
OOPS Using C++
23. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
23
Example of multiple inheritance
class X
{
protected:
int a;
public:
void getX (int m)
{
a=m;
}
void display()
{
cout<<"The number in X is
"<<a<<endl;
}
};
class Y
{
protected:
int b;
public:
void getY (int n)
{
b=n;
}
void display1()
{
cout<<"The number in Y is
"<<b<<endl;
}
};
OOPS Using C++
24. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
24
class Z: public X, public Y
{
protected:
int c;
public:
Z(int k)
{
getX(1);
getY(2);
c=k;
}
void disp()
{
display();
display1();
cout<<"the number in Z is <<c;
}
};
int main (void)
{
Z obj(3);
obj.disp();
return 0;
}
OOPS Using C++
25. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
25
Output
■ The number in X is 1
■ The number in Y is 2
■ the number in Z is 3
OOPS Using C++
26. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
26
Ambiguity
class M
{ public: void display(){cout<<“ class M”;}
};
class N
{ public: void display(){cout<<“ class N”;}
};
class P : public M , public N
{ public: void display(){cout<<“ class P”;}
};
In this case function of derived class overrides the inherited
function so when object of P calls display function it simply
calls display of P. To invoke display of M & N we use scope
resolution operator.
OOPS Using C++
27. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
27
int main ()
{
P p;
p.display();
p.M::display();
p.N::display();
p.P::display();
return 0;
}
OOPS Using C++
28. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
28
■ Inheriting one class by more than one class
leads to Hierarchical inheritance.
Z
X
W
Y
Hierarchical Inheritance
OOPS Using C++
29. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
29
Example
class college
{
protected:
char name[12];
void disp()
{
cout<<"name of college
is"<<name<<endl;}
public:
college()
{cout<<"constructor of college
is called"<<endl;
strcpy (name, "PIET");
}};
class it_dept : public college
{
int faculty;
public:
void get_faculty()
{
cout<<"enter no of faculty
members in IT" <<endl ;
cin>>faculty; }
void display()
{ disp(); // now a protected
member of it_dept
cout<<"no of teachers in IT
"<<faculty<<endl;
}
};
OOPS Using C++
30. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
30
class ece_dept : public
college
{
int faculty;
public:
void get_faculty()
{
cout<<"enter no of faculty
members in ECE"<<endl;
cin>>faculty;}
void display()
{ disp(); // now a protected
member of ece_dept
cout<<"no of teachers in
ECE "<<faculty<<endl;}};
void main()
{ it_dept C;
ece_dept E;
C.get_faculty();
E.get_faculty();
C.display();
E.display();
}
OOPS Using C++
31. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
31
OUTPUT
constructor of college is called
constructor of college is called
enter no of faculty members in IT
12
enter no of faculty members in ECE
36
name of college is PIET
no of teachers in IT 12
name of college is PIET
no of teachers in ECE 36
OOPS Using C++
32. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
32
■ Deriving one class from other derived class
leads to Multilevel inheritance.
Y
Z
Multilevel Inheritance
X
Base class
Intermediate
base class
Derived class
test
result
Student
OOPS Using C++
33. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
33
Example
class student
{
protected:
int roll_number;
public:
void get_number(int a)
{
roll_number=a;}
void put_number()
{cout<<“Roll number
is:"<<roll_number<<“n”;
}};
class test : public student
{
protected:
float sub1,sub2;
public:
void get_marks(float x, float y)
{
sub1=x;
sub2=y;}
void put_marks()
{ cout<<“Marks in sub1=
"<<sub1<<endl;
cout<<“Marks in sub2=
"<<sub2<<endl;
}
};
OOPS Using C++
34. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
34
class result : public test
{
float total;
public:
void display()
{
total=sub1+sub2;
put_number();
put_marks();
cout<<“Total ="<< total
<<endl;
}};
int main()
{
result Abc;
Abc.get_number(111);
Abc.get_marks(75.0,59.5);
Abc.display();
return 0;
}
OOPS Using C++
35. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
35
■ When more than one inheritance is used, it
is called hybrid inheritance.
Z
W
Hybrid Inheritance
Sub class of X and Y
Base class of X,Y
Sub class
of W
Sub
class of
W
Y
X
OOPS Using C++
36. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
36
Virtual base class
■ In case of hybrid inheritance shown, two
copies of W-members are created in class Z.
Int I
Int I( of W)
Int J
Int I (of W)
Int K
Int I (of X)
Int I (of Y)
Int J (of X)
Int K (of Y)
X
Z
Y
W
OOPS Using C++
37. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
37
class W
{
public:
int i;
};
class X : public W
{ public:
int j;
};
class Y: public W
{
public:
int k;
};
class Z: public X, public Y
{
public:
int sum;
};
OOPS Using C++
38. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
38
int main (void)
{
Z obj;
obj.X::i=1;
obj.j=2;
obj.k=3;
obj.sum=obj. X::i+ obj.j+obj.k;
// obj.i will be ambiguous
cout<<"the sum is "<<obj.sum;
return 0;
}
OUTPUT
The sum is 6
OOPS Using C++
39. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
39
■ If X and Y derives class W as a virtual class
then only one copy of W-members will be
inherited by X and Y.
OOPS Using C++
40. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
40
class W
{
public:
int i;
};
class X : virtual public W
{ public:
int j;
};
class Y: public virtual W
{
public:
int k;
};
class Z: public X, public Y
{
public:
int sum;
};
int main(void)
{
Z obj;
//obj.X::i=1;
obj.i=1;
obj.j=2;
obj.k=3;
obj.sum= obj.i + obj.j + obj.k;
cout<<"the sum is "<<obj.sum;
return 0;
}
OOPS Using C++
41. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
41
Abstract Classes
■ An abstract class is one that is not used to
create objects.
■ An abstract class is only designed to act as a
base class(to be inherited by other classes).
OOPS Using C++
42. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
42
Constructors in inheritance
■ Constructors play an important role in
initializing objects.
■ In case of inheritance the base class
constructors is first called of and then the
derived class constructor is called.
■ When base class contains only default
constructor then derived class may or may
not have the constructor.
■ When base class contains a constructor with
one or more arguments then it is mandatory
for the derived class to have a constructor and
pass the arguments to the base class
constructors.
OOPS Using C++
43. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
43
More about constructors….
■ When an object of derived class is created
In case of multi level inheritance constructors are
called in the order of their derivation.
class derived1 : public base
{ };
class derived2: public derived1 { };
That is base class constructor is called first, then
constructor for derived1 class is called, then
constructor for derived2 class is called.
OOPS Using C++
44. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
44
■ In case of multiple inheritance, constructors
are called in the order specified from left to
right .
■ class derived: public base1,public base2
then
derived d;
will create an object of derived class by calling
constructor for base classes base1 and then
base2
OOPS Using C++
45. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
45
Destructors in inheritance
■ When an object of derived class is
destroyed
1. In case of multi level inheritance
,destructors are called in the reverse order
of their derivation
class derived : public base1,public base2{ };
Then destructor for derived is called then
destructor for base2 is called then lastly
destructor defined in base1 will be called.
OOPS Using C++
46. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
46
Passing arguments to base class
■ When an object of derived class is created,
constructors of base class is also invoked.
■ If initialization of only derived class variables
are to be done then arguments to the
constructor can be passed in usual way.
■ But if base class constructor (invoked
implicitly) also require some arguments then
…….?
OOPS Using C++
47. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
47
■ Constructor of derived class should be
defined as
Derived constructor (arg_list) :
base1(arg_list1),base2(arg_list)……
{ body of the constructor }
■ Arg_list for base classes will contain those
arguments that are required by them,but are
passed while calling derived class
constructor.
OOPS Using C++
48. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
48
#include<iostream.h>
#include<conio.h>
#include<string.h>
class college
{
protected:
int id ;
char name[12];
void disp()
{
cout<<"name of college is
"<<name<<endl;
}
public:
college(int a)
{
id=a;
cout<<"constructor of college is
called"<<endl;
strcpy (name,"PIET");
}
};
class it_dept : public college
{
int faculty;
public:
it_dept (int a, int b) : college (a)
{ faculty=b; }
void display()
{ disp(); // now a protected member of
it_dept
cout<<“initialized college id is “<<id;
cout<<"no of teachers in IT “
<<faculty<<endl;
} };
int main()
{ clrscr();
it_dept C(10,12);
C.display();
return 0;
}
Argumen
t for base
construct
or
OOPS Using C++
49. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
49
OUTPUT
■ constructor of base college is called
■ initialized college id is 10
■ name of college is PIET
■ no of teachers in it 12
OOPS Using C++
50. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
50
■ The constructors for virtual base classes are
invoked before any non virtual base classes.
METHOD OF INHERITANCE ORDER OF EXECUTION
class B : public A
{
};
class A : public B, public C
{
};
class A : public B, virtual public C
OOPS Using C++
51. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
51
Initializing the class objects
constructor (arglist) : initialization-section
{
assignment-section
}
Example: class ABC{ int a;
public : ABC(int x)
{ a=x;
cout<< “” ABC Constructor & values”<< a;}
};
class XYZ : public ABC
{ int b,c;
public: XYZ(int i, int j): a(i),b(2*j) { c=j;
cout<< “XYZ Constructor & values”<<b<<c;}
};
main()
{ XYZ x(2,3)
}
OOPS Using C++
52. PANIPAT INSTITUTE OF ENGINEERING AND TECHNOLOGY
52
Member Classes : Nesting Of classes
class alpha { };
class beta { };
class gamma
{ alpha a;
beta b;
………
};
All objects of gamma class will contain the
objects a,b; This kind of relationship is called
containership or nesting.
OOPS Using C++