Unit-2 Inheritance in OOPs Using C++ | BCA 3rd Semester
Unit-2 Inheritance in OOPs Using C++ | BCA 3rd Semester – Hello everyone welcome to the pencilchampions.com website. This website provide unt-2 OOPs in using C++ BCA 2nd Year 3rd semester. Thankyou for visiting.
Inheritance
- The capability of a class to derive properties and characteristics from other class is called inheritance. Inheritance is one of the most important feature of object oriented programming
Super class ( Base class or parent class)
- The class whose properties are inherited in sub class is called base or super class.
Sub class ( child class or Derived class)
- The class that Inherit properties from other class is coved sub- class or derived class or child class.
Types of Inheritance
- There are five types of inheritance
- Single Inheritance
- Multiple inheritance
- Multi-level inheritance
- Hierarchical inheritance
- Hybrid Inheritance
Object
- It is a class type variable
Class
- A class is a group of common behavior and functions.
Constructor
- Constructor has the same name as that of class name and does not return any type. Also the constructor is always public. If we do not specify a constructor C++ compiler generate a default constructor for as accept no parameters and has an empty body.
- There are three type of constructor
- Default constructor
- Parameterized constructor
- Copy constructor
-
Default Constructor
- I Any Argument Each Argument Constructor. Constructors with default values ​​are called default defaults.
- What is the importance of default construct? -Tor? Will code be generated for every default constructor? Will any code be inserted by the computer into the default constructor implemented by the user behind the scenes.
- The compiler will explicitly declare the default constructor. The programmer will define it when the default constructor in the compiler needs to do some initialization of the class, if not provided. It will not touch data members or plain old data types, consider a class derived from another class, it will default constructor or class object containing another class constructor. Inserting code to call the default constructor of the base class/object.
-
Parameterized Constructor
- A default constructor has no parameters. But if you need to have parameters in a constructor, it helps you to assign initial values ​​to an object at the time of its creation. These are constructors with parameters. Using this constructor value you can provide different data members of different objects by passing appropriate. Values ​​are an argument.
- Copy Constructor
- This is the constructor of form class name(class name &). The compiler will use the copy constructor whenever you initialize an instance using values ​​from another instance of the same type. A copy constructor refers to an object of the same class as an argument.
Read more-https://pencilchampions.com/unit-1-introduction-to-object-programming-in-c-bca-2nd-year/
Destructive
- Â Destructor clean up storage longer accessible.Â
Characteristics of destroyerÂ
- We can have only one constructor for one class. .
- No Argument can be provided to the destructor, nor does it return any value.
- Destructor cannot be inherited.
- A destroyer cannot be stable.
Limitations of destructor
- These are case sensitive.
- They are not good for programs with thousands of lines of code.
- Garbage collection
- In C++ programming. Garbage collection is a form of automatic memory management. The garbage collection or junk collector attempt to reclaim garbage or memory occupied by objects that are no longer in use by the program.
- Garbage collection is essentially the opposite of manually memory management which requires the programmer to specify which object to reallocate and return to the memory system.
- Ex-Destructor
How is it different from memory allocated to normal variables?
- For common variables like int a, char, string, str [10] etc., memory is automatically allocated and deallocated. For dynamically allocated memory like –
- int *p = new int();
- This is the responsibility of the programmer
Abstract Class
- Â An abstract class has at least one pure virtual function. You can declare pure virtual. Function using pure specifier in
Declaration of a Virtual Member
- Work in class announcement.Â
- An abstract class can have a constructor.
Discover more from
Subscribe to get the latest posts sent to your email.