OOPS interview questions for freshers/OOPS Interview Questions and Answers for Freshers & Experienced

What are the characteristics of an abstract class?

An abstract class is a class that is declared as abstract. It cannot be instantiated and is always used as a base class. The characteristics of an abstract class are as follows:

* Instantiation of an abstract class is not allowed. It must be inherited.
* An abstract class can have both abstract and non-abstract methods.
* An abstract class must have at least one abstract method.
* You must declare at least one abstract method in the abstract class.
* It is always public.
* It is declared using the abstract

What are the manipulators in OOP and how it works?

Manipulators are helping functions. It is used to manipulate or modify the input or output stream. The modification is possible by using the insertion (<<) and extraction (>>) operators. Note that the modification of input or output stream does not mean to change the values of variables. There are two types of manipulators with arguments or without arguments.

. 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) which are performed on the objects.

Structure: A structure is also a user-defined collection of variables. Structures are also different data types.

How many types of constructors can be used in Java? Please explain.

There are basically three types of constructors in Java.

These are:

1. Default constructor: This constructor is without any parameter and invokes every time you create an instance of a class (object). If a class is an Employee, then the syntax of the default constructor will be Employee().
2. No-arg constructor: As the name implies, a constructor without any argument is called a no-arg constructor.
3. Parameterized constructor: Constructor with a number of parameters is called a parameterized constructor. You are required to provide arguments, i.e. initial values with respect to the data type of parameters in that constructor.

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.

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.

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.

Can we run a Java application without implementing the OOPs concept?

No. Java applications are based on Object-oriented programming models or OOPs concept, and hence they cannot be implemented without it.

However, on the other hand, C++ can be implemented without OOPs, as it also supports the C-like structural programming model

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.

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.

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) which are performed on the objects.

Structure: A structure is also a user-defined collection of variables. Structures are also different data types.

What is an object?

Object: An object is an instance of a class and also It has its own identity and behaviour.

Types of Inheritance in OOPS

Hybrid Inheritance
Multiple Inheritance
Single Inheritance
Multi-level Inheritance
Hierarchical Inheritance

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.

How is data abstraction accomplished?

Data abstraction is accomplished with the help of abstract methods or abstract classes.

What are different access modifiers in Java?

Access modifiers in Java controls access scope of class, constructor, variable, method, or data member. Various types of access modifiers are as follows:

1. Default access modifier is without any access specifier data members, class and methods, and are accessible within the same package.
2. Private access modifiers are marked with the keyword private, and are accessible only within class, and not even accessible by class from the same package.
3. Protected access modifiers can be accessible within the same package or subclasses from different packages.
4. Public access modifiers are accessible from everywhere.

Can you please highlight the difference between a class and a structure?

A class means a user-defined template from which objects are created at runtime. A class is made up of methods that provide the logic for various behaviours supported by the objects.

What is meant by a copy constructor?

A copy constructor helps in cloning objects by replicating the values from one object into another object which belongs to the same class.

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.

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.

Are class and structure the same? If not, what's the difference between a class and a structure?

No, class and structure are not the same. Though they appear to be similar, they have differences that make them apart. For example, the structure is saved in the stack memory, whereas the class is saved in the heap memory. Also, Data Abstraction cannot be achieved with the help of structure, but with class, Abstraction is majorly used.

What is a destructor?

Contrary to constructors, which initialize objects and specify space for them, Destructors are also special methods. But destructors free up the resources and memory occupied by an object. Destructors are automatically called when an object is being destroyed.

What is a copy constructor?

Copy Constructor is a type of constructor, whose purpose is to copy an object to another. What it means is that a copy constructor will clone an object and its values, into another object, is provided that both the objects are of the same class.

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.

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.

List the various types of constructors

Multiple types of constructors that are supported across multiple object-oriented programming languages are:

* Default constructor
* Copy constructor
* Static constructor
* Private constructor
* Parameterized constructor

Explain Abstraction with a real-time example.

Abstraction in object-oriented programming means hiding complex internals but to expose only essential characteristics and behavior with respect to context. In real life, an example of abstraction is an online shopping cart, say at any e-commerce site. Once you select a product and book order, you are just interested in receiving your product on time.

How things happen is not what you are interested in, as it is complex and kept hidden. This is known as abstraction. Similarly, take the example of ATM, the complexity of internals of how money is debited from your account is kept hidden, and you receive cash via a network. Similarly for cars, how petrol makes the engine run the automobile is extremely complex.

Why is a need for Object-oriented programming?

OOP provides access specifiers and data hiding features for more security and control data access, overloading can be achieved with function and operator overloading, Code Reuse is possible as already created objects in one program can be used in other programs.

Data redundancy, code maintenance, data security, and advantage of concepts such as encapsulation, abstraction, polymorphism, and inheritance in object-oriented programming provide an advantage over previously used procedural programming languages.

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

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.

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.

How does C++ support Polymorphism?

C++ is an Object-oriented programming language and it supports Polymorphism as well:

* Compile Time Polymorphism: C++ supports compile-time polymorphism with the help of features like templates, function overloading, and default arguments.

* Runtime Polymorphism: C++ supports Runtime polymorphism with the help of features like virtual functions. Virtual functions take the shape of the functions based on the type of object in reference and are resolved at runtime.

What is an object?

An object refers to the instance of the class, which contains the instance of the members and behaviors defined in the class template. In the real world, an object is an actual entity to which a user interacts, whereas class is just the blueprint for that object. So the objects consume space and have some characteristic behavior.

Why is OOPs so popular?

OOPs programming paradigm is considered as a better style of programming. Not only it helps in writing a complex piece of code easily, but it also allows users to handle and maintain them easily as well. Not only that, the main pillar of OOPs - Data Abstraction, Encapsulation, Inheritance, and Polymorphism, makes it easy for programmers to solve complex scenarios. As a result of these, OOPs is so popular.

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

What is Encapsulation?

Encapsulation is also a part of 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 are some advantages of using OOPs?

* OOPs is very helpful in solving very complex level of problems.
* Highly complex programs can be created, handled, and maintained easily using object-oriented programming.
* OOPs, promote code reuse, thereby reducing redundancy.
* OOPs also helps to hide the unnecessary details with the help of Data Abstraction.
* OOPs, are based on a bottom-up approach, unlike the Structural programming paradigm, which uses a top-down approach.
* Polymorphism offers a lot of flexibility in OOPs.

What are the main features of OOPs?

OOPs or Object Oriented Programming mainly comprises of the below four features, and make sure you don't miss any of these:

* Inheritance
* Encapsulation
* Polymorphism
* Data Abstraction

What is meant by Structured Programming?

Structured Programming refers to the method of programming which consists of a completely structured control flow. Here structure refers to a block, which contains a set of rules, and has a definitive control flow, such as (if/then/else), (while and for), block structures, and subroutines.

Nearly all programming paradigms include Structured programming, including the OOPs model.

Explain Is Java a pure Object Oriented language?

ava is not an entirely pure object-oriented programming language. The following are the reasons:

* Java supports and uses primitive data types such as int, float, double, char, etc.
* Primitive data types are stored as variables or on the stack instead of the heap.
* In Java, static methods can access static variables without using an object, contrary to object-oriented concepts.

Why use OOPs?

OOPs has clarity in programming. 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.

What is a class?

A class defines the template or the definition of an object. It is used for creating objects at run time. It provides the data structure, provides initial values for the attributes, and methods that provide the logic for the intended behaviour of the object. The class does not consume memory at runtime. A class refers to a logical entity. E.g., a vehicle may be defined as a class.

What is Structural programming?

Structural programming refers to the traditional method of programming, which is based on functions. The overall program logic is divided into functions to provide a logical structure. It is based on a top-down approach. Structural programming is suitable for easy to moderately complex problems.

What is hybrid inheritance?

Hybrid inheritance is a combination of multiple and multi-level inheritance.

What are the different types of inheritance?

* Single inheritance
* Multiple inheritance
* Multilevel inheritance
* Hierarchical inheritance
* Hybrid inheritance

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.

What are some other programming paradigms other than OOPs?

Programming paradigms refers to the method of classification of programming languages based on their features. There are mainly two types of Programming Paradigms:

* Imperative Programming Paradigm
* Declarative Programming Paradigm

Now, these paradigms can be further classified based:

1. Imperative Programming Paradigm: Imperative programming focuses on HOW to execute program logic and defines control flow as statements that change a program state. This can be further classified as:
a) Procedural Programming Paradigm: Procedural programming specifies the steps a program must take to reach the desired state, usually read in order from top to bottom.
b) Object-Oriented Programming or OOP: Object-oriented programming (OOP) organizes programs as objects, that contain some data and have some behavior.
c) Parallel Programming: Parallel programming paradigm breaks a task into subtasks and focuses on executing them simultaneously at the same time.

2. Declarative Programming Paradigm: Declarative programming focuses on WHAT to execute and defines program logic, but not a detailed control flow. Declarative paradigm can be further classified into:
a) Logical Programming Paradigm: Logical programming paradigm is based on formal logic, which refers to a set of sentences expressing facts and rules about how to solve a problem
b) Functional Programming Paradigm: Functional programming is a programming paradigm where programs are constructed by applying and composing functions.
c) Database Programming Paradigm: Database programming model is used to manage data and information structured as fields, records, and files.

What are some major Object Oriented Programming languages?

The programming languages that use and follow the Object-Oriented Programming paradigm or OOPs, are known as Object-Oriented Programming languages. Some of the major Object-Oriented Programming languages include:

* Java
* C++
* Javascript
* Python
* PHP

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.

What is meant by the term OOPs?

OOPs refers to Object-Oriented Programming. It is the programming paradigm that is defined using objects. Objects can be considered as real-world instances of entities like class, that have some characteristics and behaviors.

Search
R4R Team
R4R provides OOPS Freshers questions and answers (OOPS Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,OOPS interview questions for freshers,OOPS Freshers & Experienced Interview Questions and Answers,OOPS Objetive choice questions and answers,OOPS Multiple choice questions and answers,OOPS objective, OOPS questions , OOPS answers,OOPS MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for OOPS fresher interview questions ,OOPS Experienced interview questions,OOPS fresher interview questions and answers ,OOPS Experienced interview questions and answers,tricky OOPS queries for interview pdf,complex OOPS for practice with answers,OOPS for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .