What is OOPs?
Programmers can use objects to represent real-world circumstances thanks to object-oriented programming. Any entity with states and behaviours is an object. While methods define an item's behaviours, states reflect the characteristics or data of an entity. Objects include students, workers, books, etc. By exchanging messages, these things communicate with one another. A class is also a template for building an object. A class is required in order to generate objects. For instance, there needs to be an Employee class in order to generate an Employee object.
Difference between Procedural programming and OOPs?
Procedural Programming is based on functions.
Object-oriented programming is based on real-world objects.
It shows the data to the entire program.
It encapsulates the data.
It does not have a scope for code reuse.
It provides more scope for code reuse.
It follows the concept of top-down programming.
It follows a bottom-up programming paradigm.
The nature of the language is complicated.
It is less complicated in nature, so it is easier to modify, extend and maintain.
It is hard to modify, extend and maintain the code.
Why use OOPs?
Programming with OOP lets you package together data states and functionality to change those data states while keeping the specifics secret (Consider the analogy of a car, you can only see the steering of the car while driving, the circuitry behind it is hidden from you). As a result, OOP design produces flexible, modular, and abstract code. Because of this, it is very helpful for developing larger programs. Using classes and objects, you may include OOP into your code. The objects you construct will have the states and capabilities of the class to which they belong.
What are the basic concepts of OOPs?
The basic concepts of OOPs are:
What is Encapsulation?
Encapsulation is also a part of the OOPs concept. It refers to the bundling of data with the methods that operate on that data. It also helps to restrict any direct access to some of an object's components.
What is Abstraction?
Abstraction is an OOPs concept to build the structure of real-world objects. It "shows" only essential attributes and "hides" unnecessary information from the outside. The main focus of abstraction is to hide unnecessary details from the users. It is one of the most important concepts of OOPs.
What is method overloading?
There is a concept where two or more methods can have the same name. But they should have different parameters, different numbers of parameters, different types, or both. These methods are known as overloaded methods and this feature is called method overloading.
What is method overriding?
Method overriding is a concept of object-oriented programming.
It is a language feature that allows a subclass or child class to provide a specific implementation of a method which is already provided by one of its superclasses or parent classes.
Types of Inheritance in OOPS
Different types of inheritances in OOps are as follows:
- Single Inheritance
- Multiple Inheritance
- Multi-level Inheritance
- Multi-path Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
Become a member and get full access of SRM PLACEMENT Assests.
What are the main features of OOPs?
The main features of OOPs are given as follows:
- In OOP, you combine the code into one unit so you can specify the parameters of each piece of data. This process of wrapping up data into a single unit is called encapsulation.
- By using classes, you can generalise your object types and make your application easier to use. This is termed as an abstraction.
- The ability for a class to inherit characteristics and behaviours from another class allows for more code reuse.
- Polymorphism allows for the creation of several objects from a single, adaptable class of code.
Is it possible to call the base class method without creating an instance?
Yes, we can possibly call the base class method without creating an instance in the following 3 cases:
- If the method is static
- Calling the inherited method inside a derived class
- Calling the method using the base keyword from the sub-classes
The most popular case is that of the static methods.
What are the limitations of OOPs?
Following are some of the common limitations of OOPs:
- Size exceeds that of other programs.
- It took a lot of work to make, and it runs more slowly than other programs.
- It is inappropriate for certain types of issues.
- It takes some getting used to.
What are constructors?
The constructor has the same name as the class.
A constructor is also a special kind of method. It is used to initialize objects of the class.
Types of constructor
Types of constructors depend upon languages
- Private Constructor
- Default Constructor
- Copy Constructor
- Static Constructor
- Parameterized Constructor
What is the difference between a class and a structure?
Class: Class is basically a User-defined blueprint from which objects are created. It consists of methods ( set of instructions) that are performed on the objects.
Structure: A structure is also a user-defined collection of variables. Structures are also different data types.
A user-defined class serves layout or blueprint from which objects can be built. In essence, a class is made up of fields known as attributes and methods known as member functions that define actions. A structure is a grouping of variables of various data kinds under one heading.
What are the access modifiers?
Access modifiers or access specifiers are the keywords in object-oriented languages. It helps to set the accessibility of classes, methods, and other members.
What languages come under the oops concept?
Simula is known as the first object-oriented programming language, the most popular OOP languages are:
- Visual Basic
What is inheritance?
Whenever one class is derived from another, it is referred to as inheritance. The child class will inherit all of the parent class's public and protected properties and methods. Apart from the attributes and methods inherited from the parent class, it can also have its own additional set of features. The' extends' keyword is used to specify an inherited class.
If you derive a class from another class that is known as inheritance. The child class will inherit all the public and protected properties and methods from the parent class. The child class can also have its own properties and methods. An inherited class is defined by using the extends keyword.
What is hybrid inheritance?
The type of inheritance formed by the combination of different types of inheritances like single, multiple inheritances, etc. is classified as hybrid inheritance.
What is hierarchical inheritance?
In the case of a hierarchical inheritance, multiple subclasses inherit from a parent class. Hierarchical inheritance is a type of inheritance in which multiple classes are descended from a single parent or base class. For example, the fruit class can have 'apple', 'mango', 'banana', 'cherry' etc. as its subclasses.
Become a member and get full access of SRM PLACEMENT Assests.