Question: What is the basic of software engineering?
Answer:-
Software Engineering include analysis, development, integration and testing of software.
Notifications Mark All Read
Are you getting ready for an Object-Oriented Programming (OOP) interview? PrepInsta offers a comprehensive collection of typical OOPS Interview Questions and answers. Whether you are a fresher or an experienced programmer, you can access up-to-date information on OOPS topics. Prepare for your interview effectively with PrepInsta’s valuable resources.
Object-Oriented Programming (OOP) is a programming paradigm that is widely used in software development. It is based on the concept of “objects,” which are self-contained units that represent real-world entities or concepts and encapsulate both data and the operations that can be performed on that data. OOP is designed to make software development more organized, efficient, and easier to maintain.
Imagine you’re getting ready for a big adventure—like a treasure hunt. Getting ready for a job interview involving JAVA is a bit like that. Here’s how you can prepare:
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Ans.
A class is nothing more than a description of an object. It is a model, design, or prototype that describes an object’s features.
Ans.
Class is a blueprint or template from which objects are created and describes the contents of the object. A class should be defined before creating an object.
Ans. An object is a self-contained unit that represents a real-world entity or concept in programming, containing both data (attributes) and functions (methods) that operate on that data.
Ans.
A constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation.
Rules for constructor are:
Ans.
In Object-Oriented Programming (OOP), a destructor is a special method or function within a class that is used to clean up or release resources when an object of that class is no longer in use. It helps in proper resource management, such as releasing memory or closing files, when the object is destroyed or goes out of scope. Destructors are particularly important in languages like C++ and are automatically invoked when an object is deleted or goes out of scope.
Multiple Inheritance | Multilevel Inheritance |
---|---|
when a class inherits more than one base class | when a class inherits from another class which itself is a subclass of some other base class |
Example:- A class defining a child inherits from two base classes Mother and Father | Example:- A class describing a sport car will inherit from one base class car which in turn inherits another class Vehicle |
Ans.
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. or, BMW is a type of car, so the superclass for BMW is Class Car.
Ans.
overloading | overriding |
---|---|
two or more methods have same name but different parameters or signatures | child class redefining methods present in the base class or parent class with the same parameters/signatures |
resolved during compile time | resolved during run time |
Ans.
A friend function is capable of accessing private/protected data of a class in which it is declared as a friend in spite of not being a member of that class.
Ans.
Virtual function is a special member function that is declared within a base class and redefined by derived class to go with its own task. It is declared using a token, and is implemented by using the virtual keyword.
Ans.
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.
Ans.
Encapsulation is a feature of an entity that holds all secret data. The members of that class can only see the hidden details. Public, Protected, Private are the different levels.
Ans.
Inheritance is a concept where one class shares the structure and behavior defined in another class. Inheritance applied to one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.
Uses:-
Ans.
Yes, it is possible to call the base method without creating an instance. And that method should be the static method. Doing inheritance from that class use the Base Keyword from a derived class.
Ans.
Constructors | Methods |
---|---|
constructor name should match with the name of the class | Methods should not have the same name as the class name |
used to initialize and allocate memory of to the object | used to execute certain statements written inside them |
constructors are invoked by the system whenever objects are created | invoked when it is called |
they are invoked using new keyword while creating an instance of the class | invoked during program execution |
does not have a return type | has a return type |
cannot be inherited by subclass | can be inherited by a subclass |
Ans
Need for OOPS:-
Ans.
There are three types of constructors:
Ans.
Finalize is a method used to free up unmanaged resources and cleanup before Garbage Collection(GC). It performs memory management tasks.
Ans.
Various types of inheritance are :
Ans.
Hybrid inheritance is when a class in object-oriented programming inherits properties and behaviors from two or more parent classes. It’s like mixing different types of inheritance to reuse code and create class hierarchies.
Ans.
An interface in OOP is a set of method rules that a class must follow if it claims to implement that interface. It defines what methods a class should have but doesn’t provide their actual code. Interfaces promote a common structure among classes, enabling flexibility and consistency in code design through polymorphism.
Ans.
Yes, it is possible to run a Java program without fully utilizing OOP ideas, but because OOP is what gives Java its strength, it is usually recommended to do so for better code structure and reusability.
Ans.
Abstraction is the process of simplifying complex things by focusing on what is important and disregarding irrelevant aspects. It involves building models in programming that capture the fundamental properties of an object or system, making it easier to work with and comprehend.
Ans.
Types programming paradigms:
Impretive Programming: Imperative programming is about giving explicit step-by-step instructions, often involving changing program state with variables and control structures like loops and conditionals.
These paradigms provide several approaches to structuring and solving programming challenges
Ans.
Procedural Programming:
Object-Oriented Programming (OOP):
Ans.
Limitations of OOPS
final
):In Java and C++, you can prevent inheritance by declaring a class as final
. A final
class cannot be extended (subclassed).Ans.
Certainly, the SOLID principles of object-oriented design may be summarized as follows:
Ans.
Getter Method:
Setter Method:
Ans.
Run time polymorphism helps resolve the problem of early binding at compile time.
#include using namespace std; // This is Base class class Base { public: virtual void show() { cout << "Showing Base Class" << endl; } }; // This is Derived class function class Derived : public Base { public: // This function is declared in the base class as well void show() { cout << "Showing Derived Class" << endl; } }; int main() {
// pointer reference to base class Base *base_object;
// creating derived class object Derived derived_object;
// mapping base object to address of derived class object base_object = &derived_object; // since we use pointers so we use -> rather than .
base_object->show(); return 0; }
Abstraction | Encapsulation |
---|---|
Gives a class a general structure and leaves the implementation to the implementers. | Creates and defines an object’s permissions and constraints as well as the variables and methods that make up the object. |
Abstraction is accomplished by the use of an interface and an abstract class. | Encapsulation is accomplished by the use of four different access level modifiers: public, protected, no modifier and private. |
Class | Structure |
---|---|
Class is a referencing type. | Structure is a value type. |
CLR allocates memory for its instance in heap. | Memory is allocated on the stack. |
Support Inheritance. | Does not support Inheritance. |
Variables of a class can be assigned as null. | Structure members cannot have null values. |
Class can contain constructor/destructor | Structure does not require constructor/destructor and members can be initialized automtaically. |
Ans.
Java was designed to be a simple language and multiple inheritance introduces complexities like the diamond problem. Inheriting states or behaviors from two different type of classes is a case which in reality very rare and it can be achieved easily through an object association.
Ans.
Encapsulation is a feature of an entity that holds all secret data. The members of that class can only see the hidden details. Public, Protected, Private are the different levels.
class A { int x; A() { x = 0; } }Parameterized constructor: The constructors that take some arguments are known as parameterized constructors.
class A { int x; A(int y) { x = y; } }Copy constructor: A copy constructor is a member function that initializes an object using another object of the same class.
class A { int x; A(int y) { x = y; } // Copy constructor A(A a) { x = a.x; } }
Ans.
In C++ we create a pointer reference between parent and child classes and form an “is a” relationship between them, This is known as casting and they are of two types:-
Ans.
Access specifiers are used to hide or show data to the end user. It is used in data hiding or data abstraction.
Ans.
Abstract classes are special classes which are declared but are initialized, which means that it is not possible to create an object for the abstract class.
Ans.
Extends | Implements |
---|---|
A class can extend another class interface | A class can implement an interface |
A subclass extending superclass may not override all of the superclass methods | A class implementing interface has to implement all the methods of the interface |
A class can only extend a single superclass | A class can implement any number of interfaces |
An interface can extend more than one interfaces | An interface cannot implement any other interface |
Syntax: Class child Extend Class Parent | Syntax: Class Hybrid implements Rose |
Login/Signup to comment