Tuesday, 23 November 2021

oop_short_question

oops/c++

OOPs Interview Questions

# Large program are divied into smaller program knows as function

*most of the function share global data.

*Function transfrom data from one from to another.

*Employs top-down approach in program design.

1. Follow bottom-up approach in program design.
2. Data is hidden and can not be accessed by external function.
3. programs are divied into what are known as object .

1. Inheritance
2. Encapsulation
3. Polymorphism
4. Data Abstraction

1 It follows a bottom-up approach.
2.It models the real word well.
3. Minimizes the complexity.
4. Programmer are able to reach their goals faster.
5. Avoids unnecessary data exposure to the user by using the abstraction.
6. It allows us the reusability of code.

1. Proper planning is required.

2. Program design is tricky.

3. Classes tend to be overly generalized.

object-oriented programming structural programming
It follows a bottom-up approach. It follows a top-down approach.
It provides data hiding. Data hiding is not allowed.
It is used to solve complex problems. It is used to solve moderate problems.
It allows reusability of code that reduces redundancy of code Reusability of code is not allowed.
Class Object
It is a logical entity.. It is a real-world entity.
It is conceptual. It is real.
It does not occupy space in the memory. It occupies space in the memory.
A class can exist without any object. Objects cannot exist without a class.
It is declared once. Multiple objects can be declared as and when required.
Class Structure
Class is a group of common objects that shares common properties The structure is a collection of different data types.
It deals with data members and member functions. It deals with data members only.
It does not occupy space in the memory. It occupies space in the memory.
A class can exist without any object. Objects cannot exist without a class.
It is declared once. Multiple objects can be declared as and when required.
An instance of a class is an object. An instance of a structure is a structure variable.

1 It cannot have a return type.

2 It must have the same name as the Class name.

3. It cannot be marked as static. It cannot be marked as abstract.

4. It cannot be overridden.It cannot be final.

Constructor Method
Constructor has the same name as the class name. The method name and class name are not the same.
It creates an instance of a class. It is used to execute Java code.
It cannot be inherited by the subclass. It can be inherited by the subclass
It does not have any return type. It must have a return type.
It cannot be overridden in Java. It can be overridden in Java.
Java compiler automatically provides a default constructor Java compiler does not provide any method by default.
Procedural Oriented Programming Object-Oriented Programming
It is based on functions. It is based on real-world objects.
It follows a top-down approach. It follows a bottom-up approach.
It is less secure because there is no proper way to hide data. It provides more security.
Data is visible to the whole program.
It cannot be overridden in Java. It can be overridden in Java.
Java compiler automatically provides a default constructor Java compiler does not provide any method by default.
Copy Constructor Assignment Operator
It is an overloaded constructor. It is an operator.
It creates a new object as a copy of an existing object. It assigns the value of one object to another object both of which already exist.
If no copy constructor is defined in the class, the compiler provides one. If the assignment operator is not overloaded then the bitwise copy will be made.
Inheritance Polymorphism
Inheritance is one in which a derived class inherits the already existing class's features. Polymorphism is one that you can define in different forms.
It refers to using the structure and behavior of a superclass in a subclass. It refers to changing the behavior of a superclass in the subclass.
It supports code reusability and reduces lines of code. It allows the object to decide which form of the function to be invoked at run-time (overriding) and compile-time (overloading).

A class is simply a representation of a type of object. It is the blueprint/plan/template that describes the details of an object.

An object is an instance of a class. It has its own state, behavior, and identity.

Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.

Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.

It has flexibility and simplicity in solving complex problems. Reuseage of code is easy as Inheritance concept helps to reduce redundancy of code. Data and code are bound together by encapsulation

OOPs has features for data hiding, so private data can be store and maintain confidentiality. Problems can be divided into different parts making it simple to solve. The concept of polymorphism has flexibility for that a single entity can have multiple forms.

Abstraction is an OOPs concept to build the structure of the real-world objects. It “shows” only essential attributes and “hides” unnecessary information from the outside. The main focus of abstraction is to hide the unnecessary details from the users. It is one of the most important concepts of OOPs.

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 of parameters, or both. These methods are known as overloaded methods and this feature is called method overloading.

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 super classes or parent classes.

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.

Access modifiers or access specifiers are the keywords in object-oriented languages. It helps to set the accessibility of classes, methods, and other members.

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.

combination of multiple and multi-level inheritance is known as hybrid inheritance.

Hierarchical inheritance is basically when one base class has more than one subclasses. For example, the fruit class can have ‘apple’, ’mango’, ’banana’, ‘cherry’ etc. as its subclasses.

It Increases the execution time and effort. It also requires jumping back and forth between different classes. The parent class and the child class is always tightly coupled.

Afford modifications in the program would require changes for parent and the child class both. Inheritance requires careful implementation otherwise it would lead to incorrect results.

A superclass or base class is also a class which works as a parent to some other class/ classes.

For example, the Vehicle class is a superclass of class Bike.

A subclass is a class that inherits from another class.

For example, the class Bike is a subclass or a derived of Vehicle class.

Yes, the constructors can be overloaded by changing the number of arguments accepted by the constructor or by changing the data type of the parameters

Static polymorphism or static binding is a one kind of polymorphism which comes at compile time. example of compile-time polymorphism is: method overloading.

Dynamic polymorphism, dynamic binding or Runtime polymorphism is also part of polymorphism which is basically solved during runtime. An example of runtime polymorphism: method overriding.

Operator overloading is used to implement operators using user-defined types, based on the arguments passed along with it.

Data abstraction is one of the most important features of OOPs. It only allows important information to be displayed. It helps to hide the implementation details.

For example, while using a mobile, you know, how can you message or call someone but you don’t know how it actually happens.

This is data abstraction as the implementation details are hidden from the user.

Data abstraction can be achieved using two ways:

1. Abstract class
2. Abstract method

An abstract class is also a class which is consists of abstract methods.

These methods are basically declared but not defined and If these methods need to be used later in some subclass that time those methods haveto be exclusively defined in the subclass.

Virtual functions are also part of the functions which are present in the parent class and they are overridden by the subclass.
These functions help to achieve runtime polymorphism.

Garbage Collection is a part of automatic memory management. The Garbage collector helps to free the occupied spaces by objects. Those spaces are no longer in existence.

Zero instances will be created for an abstract class. In other words, you cannot create an instance of an Abstract Class.

An exception is a kind of message that interrupts and comes up when there is an issue with normal execution of a program. Exceptions provide a error and transfer that error to the exception handler to resolve it.

Exception handling in Object-Oriented Programming is the most important concept. It is used to manage errors. An exception handler help to throw errors and then catch the error in order to solve them.

A try/ catch block helps to handle exceptions. The try block explains a set of statements that may have an error. The catch block basically catches the exception.

An 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.

A 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.

The super keyword is used to invoke the overridden method, which overrides one of its superclass methods. This keyword allows to access overridden methods and also to access hidden members of the superclass. It also forwards a call from a constructor, to a constructor in the superclass.

Operator keyword is used for overloading.

An interface is a collection of an abstract method. If the class implements an interface, it thereby inherits all the abstract methods of an interface. Java uses Interface to implement multiple inheritances.

Early binding refers to the assignment of values to variables during design time, whereas late Binding refers to the assignment of values to variables during run time.

A pure virtual function is a function which can be overridden in the derived class but cannot be defined. A virtual function can be declared as Pure by using the operator =0.

No comments:

Post a Comment

How do you select data from a table in SQL?

Create Table How do you select data a table in SQL? The SELECT statement is used to se...