The four basic concepts of OOP are:
The four basic concepts of OOP are:
OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
Properties define the “nouns” of your classes. They let the programmer determine a look and feel of the object. For instance, if you have a class that defines a house, the class properties would describe the house’s color, size, and address. The class methods are the “verbs.” Methods define the actions carried out by your classes.
Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allowscreation of several methods with the same name which differ from each other by type of input and output of the function.
void add(int& a, int& b);
void add(double& a, double& b);
void add(struct bob& a, struct bob& b);
Static functions and classes require no instantiation. It means that you can use these classes, functions, and parameters at-will without creating and instantiating the object. Static functions are beneficial when you need quick execution of functions that don’t need other parts of the containing class. You cannot use non-static classes with static functions.
A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object.
The two major types of inheritance accessibility definitions are public and private. Private definitions restrict the method or property to the internal class. This means that external classes are not able to “see” the private definitions. You use these private methods and properties to manipulate data within the class. Public makes the methods and properties available to other classes. For instance, if you want to create a car class, you want other classes to be able to move the car. The car’s “move” method would be public, so other classes can move the car. However, you would not want other classes to be able to change aspects about the car’s engine. You would then keep engine properties private.
Some of the examples of tokens are:
Pointers are typically used in C++, but they are also relevant in other programming languages. Pointers are the actual memory location of a value. Because a pointer is an actual memory physical location, when you change a value in a pointer, you change the value in memory so it is global. When you globally change a value, it changes for all classes, methods and any code that uses that value.
An abstract class cannot be instantiated, but it can be inherited. This means that your inherited class can use the abstract class methods and properties, but the abstract class cannot be called directly. Abstract classes are good for defining global definitions for your inherited classes, so you only need to define these definitions once.
Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information.
Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.
The “this” reference refers to the current instance of the class. You typically use “this” to reference an internal property or method of the class. You will see “this” in various programming languages. Basically, “this” refers to the currently instantiated object.
Virtual function is a member function ofclass and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.
Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.
Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object. Examples are endl and setw.
Instantiation is how you create a class object. The class object is instantiated using the constructor whether that constructor has no parameters or several parameters. You need to instantiate a class before you can use it. After you instantiate your class, you can use its properties and methods. After you are finished with the class and it is out of scope, you use the class destructor to destroy it and remove it from memory.
Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.
Exception handling is a type of error correction that traps “mistakes” in your code. You want users to come across issues in a graceful exception. This graceful exception traps errors, so the program doesn’t crash. The error correction is useful when a connection to a database occurs or you accidentally configure two values incorrectly. The error handling exception shows an error to the user and allows the user to continue using the program without it shutting down.
Destructor is a method which is automatically called when the object ismade ofscope or destroyed. Destructor name is also same asclass name but with the tilde symbol before the name.
When you pass parameters to your methods, you send the methods parameters by value by default. This means that the value of the past variable only changes within the function. When the function is finished executing, the value does not stay constant. However, when you pass a parameter by reference, you actually pass a pointer to the function. A pointer is a reference to a value in memory. When you manipulate values in memory, they are global, so not only change the value within the method, you also change the physical value in memory. When the method is finished executing, the value is also changed globally, so the value is changed permanently outside of the method.