0% found this document useful (0 votes)
147 views11 pages

Imprtant Questions For Exams

Uploaded by

Danish Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views11 pages

Imprtant Questions For Exams

Uploaded by

Danish Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Difference between Procedural programming and OOPs?

Procedural Programming Oops

Procedural Programming is based on Object-oriented programming is based on real-world


functions. objects.

It shows the data to the entire


It encapsulates the data.
program.

It does not have a scope for code


It provides more scope for code reuse.
reuse.

It follows the concept of top-down


It follows a bottom-up programming paradigm.
programming.

The nature of the language is It is less complicated in nature, so it is easier to modify,


complicated. 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:

 Inheritance
 Encapsulation
 Polymorphism
 Abstraction
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
 Hierarchical Inheritance
 Hybrid Inheritance

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:

1. If the method is static


2. Calling the inherited method inside a derived class
3. Calling the method using the base keyword from the sub-classes
The most popular case is that of the static methods.

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 are accessors ?
- They are the functions in the public interface that provide accessibility to the private data
members for “read” operations.
- Example: see the getX, getY functions in the Point class.

What are mutators?


- They are the functions in the public interface that provide accessibility to the private data
members for “write” operations.
- Example: see the setX, setY functions in the Point class.

How to do inline functions work?


- In inline functions, there is no function calls, the compiler replace every instance of their
calls in the code with the body of the function saving the overhead associated with the
function call mechanism.
- “inline” keyword can be used to specify a function as an inline.
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 specifier are the keywords in object-oriented languages. It helps
to set the accessibility of classes, methods, and other members.

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.

What are the limitations of inheritance?


It Increases the execution time and effort. It also requires jumping back and forth between
different classes. The parent class and the child class are always tightly coupled. Afford
modifications in the program would require changes for the parent and the child‟s class.
Inheritance requires careful implementation otherwise it would lead to incorrect results.

What is a super class?


A super class is a class from which a subclass or child class is derived. Base class and
parent class are other names for a super class. For example, if Student is a class derived
from the Person class, then the Person class will be referred to as the super class.

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

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

What is a subclass?
A class that derives from another class is referred to as a subclass. A subclass inherits the
properties of its ancestors or parent classes. For example, the class Bike is a subclass or a
derivative of the Vehicle class.

What is Polymorphism?
Polymorphism is one of the most used and core concepts in OOP languages. It explains
the concept of different classes can be used with the same interface. Each of these classes
can have its own implementation of the interface.

What is static polymorphism?


In OOP, static polymorphism determines which method to call at compile time. For the same
trigger with static polymorphism, the object might respond differently. Function, constructor
and operator overloading are examples of static polymorphism.

What is dynamic polymorphism?


Dynamic polymorphism is a method or process that handles a call to an overridden method
during runtime rather than at compile time. It is also referred to as dynamic method dispatch
or runtime polymorphism. Using method overriding, we can create dynamic polymorphism.
An example of runtime polymorphism: is method overriding.
What is operator overloading?

The user-defined data type is given a special meaning by the operator using operator
overloading. It is a compile-time polymorphism.

Differentiate between overloading and overriding.


When two or more methods in the same class have the same name but different
parameters, this is referred to as overloading. The technique of using the same method
signature, i.e., name and parameters, in both the superclass and the child class is known as
overriding.

What is encapsulation?
Encapsulation is used to wrap the data and the code which works in a single unit together.
Example: Encapsulation allows data-hiding as the data specified in one class is hidden from
other classes.

What is the difference between public, private and protected access


modifiers?

What is data abstraction?


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.
How to achieve data abstraction?
Data abstraction can be achieved using two ways:

 Abstract class
 Abstract method
What is an abstract class?
An abstract class is also a class which is consists of abstract methods.

So what is an abstract method?

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

Differentiate between data abstraction and encapsulation.

What are virtual functions?


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.

What is a destructor?
A destructor is a method that is called automatically when an object is destroyed.

The destructor also recovers the heap space which was allocated to the destroyed object. It
also start closing the files and database connections of the object, etc.

What is a copy constructor?


By copying the members of an existing object, the copy constructor initialises the members
of a newly formed object. The argument for the copy constructor is a reference to an object
of the same class. Programmers have the option of directly defining the copy constructor.
The compiler defines the copy constructor if the programmer doesn‟t..

What is Garbage Collection(GC)?


Programming languages like C# and Java include garbage collection (GC) as a memory
recovery mechanism. A programming language that supports garbage collection (GC)
contains one or more GC engines that automatically release memory space that has been
reserved for things the application is no longer using.

What is an exception?
An exception is a kind of message that interrupts and comes up when there is an issue with
the normal execution of a program. Exceptions provide an error and transfer it to the
exception handler to resolve it. The state of the program is saved as soon as an exception is
raised.

What is exception handling?


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.

What is the difference between an error and an exception?

What is a try/ catch block?


The terms “try” and “catch” describe how to handle exceptions brought on by coding or data
mistakes while a program is running. The section of code where exceptions occur is called a
try block. Exceptions from try blocks are caught and handled in a catch block.

What is a finally block?


Finally designates the section of code that works with the try keyword. It specifies code that
is always executed before the method is finished, immediately behind the try and any catch
blocks. Regardless of whether an exception is thrown or caught, the finally block is always
executed.

Can you call the base class method without creating an instance?
Yes, you are allowed to call the base class without instantiating it but there are some
conditions that are applicable:

 If it is a static method
 The base class is inherited by some other subclass

What is the difference between a class and an object?


Any real-world entity is called an object. The object has specific properties and behaviours,
and the similar type of objects having similar features and behaviours are grouped as a
class. Hence, Class is a blueprint of objects, and an object is an instance of a class.

Ex: -

1. An Animal is a class, and cat, dog, etc., are objects with common properties like name, type, and common
behaviors like speaking, walking, running, etc.

2. Mobile is a class, and Nokia, moto, iPhone, etc., are objects with common properties like modal_no, color,
etc., and common behaviors like audio_calling, video_calling, music, etc.

What are ‘access specifiers’?


Access specifiers are the keywords in any programming language used to specify the
Class‟s, method‟s, interface‟s and variable‟s behaviour concerning its accessibility. The
access specifiers in C++ Programming are public, private, and protected.

Can you create an instance of an abstract class?


No, an instance of the Abstract class cannot be created. To implement the abstract Class,
abstract methods, the Abstract Class should be extended by another class, and the object of
the implementation class can be created.

What are pure virtual functions?


A pure virtual function/method is a function whose implementations are not provided in the
base class, and only a declaration is provided. The pure virtual function can have its
implementation code in the derived class; otherwise, the derived class will also be
considered an abstract Class. The Class containing pure virtual functions is abstract.

Differentiate between an abstract class and an interface?


An interface can have only abstract methods, but an Abstract class can have abstract and
non-abstract methods.

The interface should be used if just the requirement specification is known and nothing about
implementation. If the implementation is known, but partially, then an abstract class should
be used. If the implementation is known completely, then a concrete Class should be used.

What are the characteristics of an abstract class?


1. A class having at least one pure virtual function is called an Abstract class.
2. An Abstract class cannot have objects created, i.e., an abstract class cannot be instantiated,
but Object references can be created.
3. An Abstract class can have non-abstract functions and pure virtual functions also.
4. The pure virtual function can have its implementation code in the derived class; otherwise, the
derived class will also be considered an abstract Class

What is constructor chaining?


Constructor chaining is a method to call one constructor from another concerning a current
object reference. It can be done in two ways: –

1. Using the “this” keyword, the reference can be made to the constructor in the current class.
2. To call the constructor from the base class “super” keyword will be used.

The list of operators which can be overloaded:

 Arithmetic Operators like %, +, -, *, /


 Unary Operators like ++, --,!
 Relational Operators like ==, !=, >=, <=
 Logical operators like && and ||
 Assignment operators like =, +=,*=, /=,-=, %=
 Subscript operator [ ]
 Bitwise operators like &, |, <<, >>, ^, ~

Note: Only existing operators in C++ can be overloaded and the overloaded operator must
have an operand of the user-defined type.

List of Operators That Cannot Be Overloaded in C++


The list of operators which cannot be overloaded is as follows:

 Conditional or Ternary Operator (?:) cannot be overloaded.


 Size of Operator (sizeof) cannot be overloaded.
 Scope Resolution Operator (::) cannot be overloaded.
 Class member selector Operator (.) cannot be overloaded.
 Member pointer selector Operator (.*) cannot be overloaded.

What are the types of variables in OOP?


Variables are basic units to store data in RAM for Java programs.

Variables should be declared before using them in Java programming. Variable initialization
can be static or dynamic. The syntax for variable declaration and static initialization is: –

Types of variables
 Primitive Variables: It is used to represent primitive values like int, float, etc.
 Instance Variables: Variables whose value varied from object to object are instance
variables. For every object, a separate copy of the instance variable is created. Instance
variables are declared within the Class and outside any method/block/constructor
 Static variables: For static Variables, a single copy of the variable is created, and that copy
is shared between every Class object. The static variable is created during class loading and
destroyed at class unloading.
 Static variables can be accessed directly from the static and instance area. We are not
required to perform initialization explicitly for static variables, and JVM will provide default
values.
 Local Variables: Variables declared inside a method or block or constructor are local
variables. Hence the scope of local variables is the same as the block‟s scope in which we
declared that variable.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy