Class Hierarchy In Object Oriented Programming Computer Science
One of the corner stone's of object-oriented programming is inheritance because it creates a different classifications of hierarchical. To make unique the few other specific classes whenever the class is inherited. Super class is called whenever a class in inherited. And the class which is not inherited is named as sub class. Her it is clear that sub class will appear by super class means specialised version. In this type of version its add unique elements whenever an methods and instance variables re inherited.
Example of class hierarchyInheritance basicsTo inherit a class you simply incorporate the definition of one class into another.
The constructor and destructor of a base class are not inherited the assignment operator is not C++ classes can inherit both data and function members from other classes.
Some of the exceptions to be noted in C++ inheritance are inherited functions and friend classes of the base class are also not inherited.
The protected and public variables or members of the super class are all accessible in the derived class. But a private member variable not accessible by a sub class.
The protected and private members will not accessible outside the class. But a sub class is given access to protected members of the super class.
Exceptions to be noted by C++ inheritance
The non inherited base classes are constructor and destructor
Assignment operator
Friend classes and functions
We have notations to be remembered that in derived class accessible by a base class like members or public/protected variables. But in derived class private member variable will not accessible. Base classes which are declared to be virtual; this is called virtual inheritance. Inheritance graph exists base class that ensures only one instance avoid some ambiguity problems of multiple inheritance. This type of inheritance will not found in most the other languages, which allow derived class more than one base classes and also allow more elaborate inheritance relationships. In derived class, abstract base class normally explicit defined by member functions and not inherited implicitly.
Multiple inheritancePublic inheritancePublic syntax:class Car : public Vehicle {
public:
... }; Types of InheritancesSingle inheritance
Syntax: class classname2
{//code
};Class classname3: public classname2
{//code
};Multiple inheritance
Syntax: class classname1
{//code
};Class classname2: public classname1
{//code
};Class classname3: public classname2
{//code
};Hierarchal inheritance
Syntax: class classname1
{//code
};Class classname2
{//code
};Class classname3: public classname1,public classname2
{//code
};Multi level inheritance
Hybrid inheritance
Virtual functionIn case the sub class needs some different functionality for the same functions start stop and run then the super class should implement the concept of virtual functions.
At the time of compilation, the definition that gives a correct function call by default i should match in c++ is named as static binding. And same for dynamic binding but it will find a correct function call at the time of running(run time). Declaration is given by virtual keyword and there is a specific function that dynamic binding will use at the time of compilation.
Problems which solves by the concept of the virtual function:Whenever a base class is inherited by a derived class, then derived class objects are referred to as derived class type or base type class. If base class overridden by derived class, then the method is ambiguous behavior. This resolves ambiguity by distinguishing non virtual and virtual functions. Functioning of question is designated, derived is called next after base class is called this is in virtual functioning and its reciprocal in non virtual functioning, base is called after derived class is called. This type is called static binding and dynamic binding.
The problems in virtual functioning can be solved by defining programmer firstly declaring functions into base class and then redefined in each derived class. In C++ virtual functions and methods are declared by virtual keywords.
Properties
At run time function call can be resolved.
Usually in this derived class different functionality are appeared
The functions are declared with virtual keyword
It is a class member function.
All the time base class function will be called whenever an function is not declared virtual. During the compile time the function address bound will be statically found. Now function is declared as virtual then he candidate for derived class and run time linking will be invoked.
Abstract classAbstract class which is designed is specifically used as a base class. It should contain at least one virtual function. A pure virtual function is declare by using a pure specifier (=0).If any class contains at least one abstract function, then such a class is called abstract class.
Syntax:
abstract class classname
{Member variables
+Concrete methods
+Abstract methods
}An abstract class can have any know of implemented methods and abstract methods. Reference variable of type abstract class can be created but object of type abstract cannot be created. Every abstract class requires subclass. Sub class can inherit all the properties of abstract base class including dummy methods (abstract methods) so from the sub class we must override the abstract methods which are inherited, otherwise derived class becomes abstract class.
Polymorphism:Poly stands for many and morphism stands for forms
Polymorphism= many terms.
It any function behaves differently within the same class or different classes such a behavior is known as polymorphism
Polymorphism
Compile time
Article name: Class Hierarchy In Object Oriented Programming Computer Science essay, research paper, dissertation