0% found this document useful (0 votes)
46 views20 pages

5.how Many Instances of An Abstract Class Can Be Created-4 Class 1byte 6

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 20

1.

Constructors-
are generally used for instantiating an object. The task of
constructors is to initialize(assign values) to the data
members of the class when an object of class is created.In
Python the __init__() method is called the constructor and is
always called when an object is created

• There are three types of constructors: Default, No-arg


constructor and Parameterized.

2.Overloading is the ability of a function or an operator to
behave in different ways based on the parameters that are
passed to the function, or the operands that the operator
acts on

3.Overriding is the property of a class to change the


implementation of a method provided by one of its base
classes. ... In Python method overriding occurs by
simply defining in the child class a method with the same name
of a method in the parent class

4.) Object is an instance of a class. Class is a blueprint or


template from which objects are created. 2) Object is a real
world entity such as pen, laptop, mobile, bed,
keyboard, mouse, chair etc.
Python is an object oriented programming language.
Almost everything in Python is an object, with its properties
and methods. A Class is like an object constructor, or a
"blueprint" for creating objects.

5.How many instances of an abstract class can be created-4


Class 1byte

6.Runtime polymorphism is nothing but method overriding. It


works in tandem with inheritance. Method overriding is
concept where even though the method name and
parameters passed is similar, the behavior is different based on
the type of object. class Animal: def makeNoise(self):
raise NotImplementedError. Python.

7.A trigger is a special type of stored procedure that


automatically runs when an event occurs in the database
server. DML triggers run when a user tries to modify
data through a data manipulation language (DML) event. DML
events are INSERT, UPDATE, or DELETE statements on
a table or view.

8.RDBMS stands for Relational Database Management


Systems.. All modern database management systems like
SQL, MS SQL Server, IBM DB2, ORACLE, My-SQL
and Microsoft Access are based on RDBMS. It is called
Relational Data Base Management System (RDBMS)
because it is based on relational model introduced by E.F.
Codd.

9.NoSQL databases (aka "not only SQL") are non tabular, and store
data differently than relational tables. NoSQL databases come in a
variety of types based on their data model. The main types are
document, key-value, wide-column, and graph.
A relational table is a table of columns or fields that
describe a listing (or rows) of data, similar to an Acoustic
Campaign database. For example, a relational table
may contain fields such as customer ID, transaction number,
product purchased, product price, sale date, and
purchase location.

10.COMMIT permanently saves the changes made by current


transaction. ROLLBACK undo the changes made by current
transaction. Transaction can not undo changes
after COMMIT execution. Transaction reaches its previous
state after ROLLBACK. When transaction is
successful, COMMIT is applied

11.There are four basic types of SQL joins: inner, left, right,
and full
⁃ Inner Join / Simple Join.
⁃ Left Outer Join / Left Join.
⁃ Right Outer Join / Right Join.
⁃ Full Outer Join.
⁃ Cross Join.
⁃ Self Join.

12.INNER JOIN: returns rows when there is a match in both


tables. LEFT JOIN: returns all rows from the left table, even if
there are no matches in the right table. RIGHT JOIN:
returns all rows from the right table, even if there are no
matches in the left table. ... Note :It will return all
selected values from both tables.

13.Normalization is a database design technique that reduces


data redundancy and eliminates undesirable characteristics like
I nsertion, Update and Deletion Anomalies.
Normalization is the process of organizing data into a
related table; it also eliminates redundancy and increases the
integrity which improves performance of the
query. To normalize a database, we divide the database into
tables and establish relationships between the tables

14.Socket programming is a way of connecting two nodes on a


network to communicate with each other. One socket(node)
listens on a particular port at an IP, while other
socket reaches out to the other to form a connection. Server
forms the listener socket while client reaches out to
the server.

15.process is the instance of a computer program that is being


executed by one or many threads. It contains the program code
and its activity. Depending on the operating system (OS),
a process may be made up of multiple threads of execution
that execute instructions concurrently.

16.Encapsulation is one of the fundamental concepts in


object-oriented programming (OOP). It describes the idea of
bundling data and methods that work on that data within one
unit, e.g., a class in Java. This concept is also often used to
hide the i internal representation, or state, of an object
from the outside.

17.Abstraction is the concept of object-oriented


programming that "shows" only essential attributes and
"hides" unnecessary information. ... Abstraction is
selecting data from a larger pool to show only relevant details
of the object to the user. It helps in reducing
programming complexity and efforts.

18.The three types of encapsulation in OOP


• Member Variable Encapsulation. In Object Oriented
Programming, all data members should be declared as
Private members of the Class. ...
• Function Encapsulation. Functions used only for internal
implementation of your API must always be declared
Private. ...
• Class Encapsulation.

19.Semaphores are integer variables that are used to solve


the critical section problem by using two atomic operations,
wait and signal that are used for process
synchronization

20.database (necessary to normalise)is


normalized to minimize redundancy (duplicate data) and to
ensure only related data is stored in each table. It also
prevents any issues stemming from database modifications
such as insertions, deletions, and updates

21.Paging is a memory management scheme that eliminates


the need for contiguous allocation of physical memory. This
scheme permits the physical address space of a
process to be non – contiguous

22.Acid properties:A transaction in a database system must


maintain Atomicity, Consistency, Isolation, and Durability −
commonly known as ACID properties − in order to
ensure accuracy, completeness, and data integrity.

23.JOINS in SQL are commands which are used to combine


rows from two or more tables, based on a related column
between those tables. There are predominantly used when a
user is trying to extract data from tables which have one-to-
many or many-to-many relationships between them.

24.The self is used to represent the instance of the class. With


this keyword, you can access the attributes and methods of
the class in python. It binds the attributes with the given
arguments. The reason why we use self is that Python does
not use the '@' syntax to refer to instance attributes

25.Integer data type: ... Like wise, 4 byte (32 bit) of memory
for 32 bit processor and 8 byte (64 bit) of memory for 64 bit
processor is allocated for int datatype. int (2 byte) can
store values from -32,768 to +32,767. int (4 byte) can store
values from -2,147,483,648 to +2,147,483,647.

26. The sizeof operator is the most common operator in C. It


is a compile-time unary operator and used to compute the size
of its operand. It returns the size of a variable. It can be applied
to any data type, float type, pointer type variables

27. The kernel is a computer program at the core of a


computer's operating system that has complete control over
everything in the system. It is the "portion of the operating
system code that is always resident in memory", and facilitates
interactions between hardware and software components.

28.MongoDB is popular among new developers due to it's


flexibility and ease of usage. Even though it's easy to use it still
provides all the capabilities needed to meet the
complex requirements of modern applications. A lot of
developers like Mongo because it stores all of it's documents in
JSON

29.ER model stands for an Entity-Relationship model. It is


a high-level data model. This model is used to define the data
elements and relationship for a specified system. It
develops a conceptual design for the database. It also develops
a very simple and easy to design view of data

30.A primary key is a field in a table which uniquely identifies


each row/record in a database table. Primary keys must
contain unique values. A primary key column cannot have
NULL values. ... When multiple fields are used as a primary
key, they are called a composite key.

31.An application stack is a group of software programs that


work together to achieve a common goal. Typical application
stacks include closely related software
applications that aid in the completion of a certain task. It is
important not to confuse software stacks with
application stacks.

32.A linked list is a sequence of data structures, which are


connected together via links. Linked List is a sequence of links
which contains items. Each link contains a
connection to another link. Linked list is the second most-
used data structure after array.

33.a doubly linked list is a linked data structure that consists


of a set of sequentially linked records called nodes. Each node
contains three fields: two link fields (references to
the previous and to the next node in the sequence of nodes)
and one data field.

34.A pointer is a variable whose value is the address of


another variable, i.e., direct address of the memory location.
Like any variable or constant, you must declare a pointer
before using it to store any variable address.

35.Destructors in C++ are members functions in a class that


delete an object. They are called when the class object goes
out of scope such as when the function ends, the program
ends, a delete variable is called

36.Compile Time Polymorphism: Whenever an object is


bound with their functionality at the compile-time, this is known
as the compile-time polymorphism. At compile-time,
java knows which method to call by checking the method
signatures. So this is called compile-time polymorphism
or static or early binding

2. What is Object Oriented Programming?

Object-Oriented Programming(OOPs) is a type of programming


that is based on objects rather than just functions and
procedures. Individual objects are grouped into classes. OOPs
implements real-world entities like inheritance, polymorphism,
hiding, etc into programming. It also allows binding data and
code together.
3. Why use OOPs?
• OOPs allows clarity in programming thereby allowing
simplicity in solving complex problems
• Code can be reused through inheritance thereby reducing
redundancy
• Data and code are bound together by encapsulation
• OOPs allows data hiding, therefore, private data is kept
confidential
• Problems can be divided into different parts making it simple
to solve
• The concept of polymorphism gives flexibility to the program
by allowing the entities to have multiple forms

4. What are the main features of OOPs?


• Inheritance
• Encapsulation
• Polymorphism
• Data Abstraction
Classes and Objects OOPs Interview Questions
5. What is an object?

An object is a real-world entity which is the basic unit of OOPs


for example chair, cat, dog, etc. Different objects have different
states or attributes, and behaviors.
6. What is a class?

A class is a prototype that consists of objects in different states


and with different behaviors. It has a number of methods that
are common the objects present within that class.
7. What is the difference between a class and a structure?

Class: User-defined blueprint from which objects are created. It


consists of methods or set of instructions that are to be
performed on the objects.

Structure: A structure is basically a user-defined collection of


variables which are of different data types.
8. Can you call the base class method without creating an instance?

Yes, you can call the base class without instantiating it if:
• It is a static method
• The base class is inherited by some other subclass
10. What is inheritance?

Inheritance is a feature of OOPs which allows classes inherit


common properties from other classes. For example, if there is
a class such as ‘vehicle’, other classes like ‘car’, ‘bike’, etc can
inherit common properties from the vehicle class. This property
helps you get rid of redundant code thereby reducing the
overall size of the code.
11. What are the different types of inheritance?
• Single inheritance
• Multiple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance

13. What is hybrid inheritance?

Hybrid inheritance is a combination of multiple and multi-level


inheritance.
14. What is hierarchical inheritance?

Hierarchical inheritance refers to inheritance where one base


class has more than one subclasses. For example, the vehicle
class can have ‘car’, ‘bike’, etc as its subclasses.
15. What are the limitations of inheritance?
• Increases the time and effort required to execute a program
as it requires jumping back and forth between different
classes
• The parent class and the child class get tightly coupled
• Any modifications to the program would require changes both
in the parent as well as the child class
• Needs careful implementation else would lead to incorrect
results
16. What is a superclass?

A superclass or base class is a class that acts as a parent to


some other class or classes. For example, the Vehicle class is
a superclass of class Car.
17. What is a subclass?

A class that inherits from another class is called the subclass.


For example, the class Car is a subclass or a derived of Vehicle
class.
OOPs Interview Questions – Polymorphism

18. What is polymorphism?

Polymorphism refers to the ability to exist in multiple forms.


Multiple definitions can be given to a single interface. For
example, if you have a class named Vehicle, it can have a
method named speed but you cannot define it because
different vehicles have different speed. This method will be
defined in the subclasses with different definitions for different
vehicles.
19. What is static polymorphism?

Static polymorphism (static binding) is a kind of polymorphism


that occurs at compile time. An example of compile-time
polymorphism is method overloading.
20. What is dynamic polymorphism?

Runtime polymorphism or dynamic polymorphism (dynamic


binding) is a type of polymorphism which is resolved during
runtime. An example of runtime polymorphism is method
overriding.
21. What is method overloading?

Method overloading is a feature of OOPs which makes it


possible to give the same name to more than one methods
within a class if the arguments passed differ.
22. What is method overriding?

Method overriding is a feature of OOPs by which the child class


or the subclass can redefine methods present in the base class
or parent class. Here, the method that is overridden has the
same name as well as the signature meaning the arguments
passed and the return type.
23. What is operator overloading?

Operator overloading refers to implementing operators using


user-defined types based on the arguments passed along with
it.

25. What is encapsulation?


Encapsulation refers to binding the data and the code that
works on that together in a single unit. For example, a class.
Encapsulation also allows data-hiding as the data specified in
one class is hidden from other classes.
26. What are ‘access specifiers’?

Access specifiers or access modifiers are keywords that


determine the accessibility of methods, classes, etc in OOPs.
These access specifiers allow the implementation of
encapsulation. The most common access specifiers are public,
private and protected. However, there are a few more which
are specific to the programming languages.

28. What is data abstraction?

Data abstraction is a very important feature of OOPs that


allows displaying only the important information and hiding the
implementation details. For example, while riding a bike, you
know that if you raise the accelerator, the speed will increase,
but you don’t know how it actually happens. This is data
abstraction as the implementation details are hidden from the
rider.
29. How to achieve data abstraction?

Data abstraction can be achieved through:


• Abstract class
• Abstract method
30. What is an abstract class?

An abstract class is a class that consists of abstract methods.


These methods are basically declared but not defined. If these
methods are to be used in some subclass, they need to be
exclusively defined in the subclass.

31. Can you create an instance of an abstract class?

No. Instances of an abstract class cannot be created because it


does not have a complete implementation. However, instances
of subclass inheriting the abstract class can be created.
32. What is an interface?

It is a concept of OOPs that allows you to declare methods


without defining them. Interfaces, unlike classes, are not
blueprints because they do not contain detailed instructions or
actions to be performed. Any class that implements an interface
defines the methods of the interface.

34. What are virtual functions?

Virtual functions are functions that are present in the parent


class and are overridden by the subclass. These functions are
used to achieve runtime polymorphism.
35. What are pure virtual functions?
Pure virtual functions or abstract functions are functions that
are only declared in the base class. This means that they do
not contain any definition in the base class and need to be
redefined in the subclass.
36. What is a constructor?

A constructor is a special type of method that has the same


name as the class and is used to initialize objects of that class.
37. What is a destructor?

A destructor is a method that is automatically invoked when an


object is destroyed. The destructor also recovers the heap
space that was allocated to the destroyed object, closes the
files and database connections of the object, etc.
38. Types of constructors

Types of constructors differ from language to language.


However, all the possible constructors are:
• Default constructor
• Parameterized constructor
• Copy constructor
• Static constructor
• Private constructor
39. What is a copy constructor?

A copy constructor creates objects by copying variables from


another object of the same class. The main aim of a copy
constructor is to create a new object from an existing one.
40. What is the use of ‘finalize’?
Finalize as an object method used to free up unmanaged
resources and cleanup before Garbage Collection(GC). It
performs memory management tasks.
41. What is Garbage Collection(GC)?

GC is an implementation of automatic memory management.


The Garbage collector frees up space occupied by objects that
are no longer in existence.
44. What is a final variable?

A variable whose value does not change. It always refers to the


same object by the property of non-transversity.
OOPs Interview Questions – Exception Handling
45. What is an exception?

An exception is a kind of notification that interrupts the normal


execution of a program. Exceptions provide a pattern to the
error and transfer the error to the exception handler to resolve
it. The state of the program is saved as soon as an exception is
raised.
46. What is exception handling?

Exception handling in Object-Oriented Programming is a very


important concept that is used to manage errors. An exception
handler allows errors to be thrown and caught and implements
a centralized mechanism to resolve them.
48. What is a try/ catch block?

A try/ catch block is used to handle exceptions. The try block


defines a set of statements that may lead to an error. The catch
block basically catches the exception.
49. What is a finally block?

A finally block consists of code that is used to execute


important code such as closing a connection, etc. This block
executes when the try block exits. It also makes sure that finally
block executes even in case some unexpected exception is
encountered.
OOPs Interview Questions – Limitations of OOPs
50. What are the limitations of OOPs?
• Usually not suitable for small problems
• Requires intensive testing
• Takes more time to solve the problem
• Requires proper planning
• The programmer should think of solving a problem in terms of
objects

2. What is the need for OOPs?

There are many reasons why OOPs is mostly preferred, but the most

important among them are:

• OOPs helps users to understand the software easily, although they

don’t know the actual implementation.

• With OOPs, the readability, understandability, and maintainability of

the code increase multifold.

• Even very big software can be easily written and managed easily using
OOPs.
17. How much memory does a class occupy?

Classes do not consume any memory. They are just a blueprint based

on which objects are created. Now when objects are created, they

actually initialize the class members and methods and therefore

consume memory.

18. Is it always necessary to create objects from class?

No. An object is necessary to be created if the base class has non-static

methods. But if the class has static methods, then objects don’t need to

be created. You can call the class method directly in this case, using the

class name.

24. Explain Inheritance with an example?

Inheritance is one of the major features of object-oriented programming,

by which an entity inherits some characteristics and behaviors of some

other entity and makes them their own. Inheritance helps to improve and

facilitate code reuse.

Let me explain to you with a common example. Let's take three different

vehicles - a car, truck, or bus. These three are entirely different from one

another with their own specific characteristics and behavior. But. in all

three, you will find some common elements, like steering wheel,
accelerator, clutch, brakes, etc. Though these elements are used in

different vehicles, still they have their own features which are common

among all vehicles. This is achieved with inheritance. The car, the truck,

and the bus have all inherited the features like steering wheel,

accelerator, clutch, brakes, etc, and used them as their own. Due to this,

they did not have to create these components from scratch, thereby

facilitating code reuse.

36. What are access specifiers and what is their significance?

Access specifiers, as the name suggests, are a special type of

keywords, which are used to control or specify the accessibility of

entities like classes, methods, etc. Some of the access specifiers or

access modifiers include “private”, “public”, etc. These access specifiers

also play a very vital role in achieving Encapsulation - one of the major

features of OOPs.

37. What is an exception?

An exception can be considered as a special event, which is raised


during the execution of a program at runtime, that brings the execution

to a halt. The reason for the exception is mainly due to a position in the

program, where the user wants to do something for which the program is

not specified, like undesirable input.

Manipulators are the functions which can be used in


conjunction with the insertion (<<) and extraction (>>)
operators on an object. Examples are endl and setw.

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.

12) What is a virtual function? A virtual function is a member function of a

class, 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.A virtual function can be declared using a

token(virtual) in C++. It can be achieved in C/Python Language by using

function pointers or pointers to function.

13) What is a friend function?

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.

A friend can be declared anywhere in the class declaration, and it cannot be

affected by access control keywords like private, public, or protected

Yes, it is possible to call the base method without creating an instance. And

that method should be “Static method.”Doing Inheritance from that class.-Use


Base Keyword from a derived class.

THIS pointer refers to the current object of a class. THIS keyword is used as a

pointer which differentiates between the current object with the global object. It

refers to the current object.

The default access modifier of a class is Internal and the default access

modifier of a class member is Private.

You might also like