1. What is OOPS?
OOPs, short for Object-Oriented Programming, is a programming paradigm centred around the concept of objects. Objects can be thought of as concrete representations of entities, such as classes, in the real world, each possessing distinct attributes and behaviours.

2. Why we should use 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.

3. Mention major Object-Oriented Programming languages.
Programming languages that adhere to the Object-Oriented Programming paradigm, often abbreviated as OOPs, are classified as Object-Oriented Programming languages. Notable examples of major Object-Oriented Programming languages encompass:
•Java
•C++
•JavaScript
•Python
•Visual Basic
•.NET
•Ruby
•Scala
•PHP

4. Explain the difference between Procedural programming and OOPs?
Some of the key distinctions between procedural programming and OOPs:
Procedural Programming OOPs (Object-Oriented Programming)
It is structured around functions. Based on real-world objects.
Data is visible and accessible throughout the entire program. Encapsulates data, providing better data security.
Follows a top-down programming approach. Follows a bottom-up programming paradigm.
More complex language in nature where Code modification, extension, and maintenance can be challenging. Less complex in nature, making it easier to modify, extend, and maintain code.
Limited scope for code reuse. Offers extensive scope for code reuse through the use of classes and objects.

5. What are the main concepts of OOPS?
The basic concepts of OOPs are:
•Inheritance
•Encapsulation
•Polymorphism
•Abstraction

6. What is Encapsulation?
Encapsulation is the practice of combining data and the associated methods that manipulate that data. This approach also serves to limit direct access to certain components within an object.
Main two key features of Encapsulations are:
Data Binding: Imagine Encapsulation as the act of encapsulating everything needed to perform a task within a capsule and then offering that capsule to the user.
Data Hiding: Encapsulation entails bundling essential data and methods while concealing extraneous details from the average user.

In essence, Encapsulation is the practice of uniting data members and methods within a program to execute a specific task, all while shielding irrelevant details from view.

7. What is Abstraction?
Abstraction selectively reveals only the vital characteristics while concealing unnecessary details from external view. The primary goal of abstraction is to shield users from irrelevant intricacies.
For instance, think of a mobile phone – you only need to understand how to operate it, not the intricate wiring inside. Abstraction achieves this level of simplification.

8. What is an interface?
An interface is a distinct class type that includes method declarations without their actual definitions. Inside an interface, only method declarations are permitted. Objects cannot be created directly from an interface. Instead, to utilize an interface, you must implement it by providing concrete method implementations.

9. What is Polymorphism?
Polymorphism is the concept that allows code, data, methods, or objects to exhibit varying behaviours based on different situations or contexts. That means different classes can be used under the same interface, and each of these classes can provide its unique implementation of the interface. OOP languages commonly feature two types of polymorphism: compile-time polymorphism and run-time polymorphism.

10. What is Compile time (Static) Polymorphism?
This form of polymorphism is also known as “static polymorphism” or “early binding” because the method or function to be called is determined at compile time based on the number and types of arguments passed to it. It is efficient and generally used when the number of arguments or the types of arguments are known at compile time. This is primarily achieved through function overloading and operator overloading.
Function overloading allows you to define multiple functions in the same scope with the same name but different parameters. The compiler selects the appropriate function to call based on the number or types of arguments provided during the function call.
Operator overloading enables you to define custom behaviors for operators when used with user-defined classes. For example, you can define how the + operator works for objects of your class.

11. What is Run time (Dynamic) Polymorphism?
This form of polymorphism is also known as “dynamic polymorphism” or “late binding,” is achieved through the use of virtual functions and inheritance. Runtime polymorphism allows the selection of the appropriate function or method to be deferred until runtime, based on the actual type of object being referred to.
Inheritance: Runtime polymorphism relies on the concept of inheritance, where one class (the derived or child class) inherits the properties and methods of another class (the base or parent class).
Virtual Functions: To enable runtime polymorphism, you declare a function in the base class as “virtual.” This means that the function can be overridden by a function with the same signature in a derived class.

12. What is “Inheritance” in OOPS?
Inheritance, in object-oriented programming, is the process of creating a new class (the child or derived class) that inherits the properties and methods (public and protected) of an existing class (the parent or base class). In addition to the inherited attributes and methods, the child class can introduce its own unique attributes and methods. This relationship is established using the ‘extends’ keyword to specify the parent class.

13. Explain types of Inheritance available in OOPS?
Types of inheritance available in OOPS:
•Single inheritance: When one class is derived from another base class, it is referred to as single inheritance.
•Multiple inheritances: When one class is derived from multiple base class, it is referred to as multiple inheritance.
•Multi-level inheritance: When one class is derived from another class which again is derived from another base class then it is referred to as multi-level inheritance.
•Hierarchical inheritance: When multiple classes are descended from a single parent or base class then it is referred to as Hierarchical inheritance.
•Hybrid inheritance: when multiple forms of inheritance, such as single inheritance, multiple inheritance, and multilevel inheritance, within a single program or class hierarchy. It is a way to create complex class relationships by mixing and matching various inheritance types to meet the specific requirements of a program. This allows for a higher degree of flexibility and expressiveness in designing class hierarchies to model real-world relationships.

14. What is method overloading and how is it different from method overriding?
Overloading is a form of compile-time polymorphism that allows an entity to have multiple implementations with the same name. Examples include method overloading and operator overloading.
Overriding is a runtime polymorphism feature where an entity shares the same name, but its implementation can change dynamically during execution. A common example is method overriding

15. What is a class, also define subclass and superclass?
A class serves as a user-defined blueprint used for creating objects. It encompasses methods, which are sets of instructions executed on those objects.
The subclass is also known as child class, which inherits from another class.
The superclass is also known as parent class, which allows subclass to inherit from itself.

16. What is an object?
An object represents an instance of a class, encapsulating the attributes and behaviors defined in the class template. In the physical world, an object is a tangible entity with which a user interacts, while a class serves as the blueprint for creating such objects. Consequently, objects occupy memory space and exhibit specific characteristic behaviors.

17. What is a constructor?
Constructors are distinct methods sharing the same name as the class. They hold the unique responsibility of initializing objects. For instance, if you have a class named ‘AnyClass,’ when you create an instance of this class, you use the following syntax:
AnyClass AnyClassObject = new AnyClass();
Above the method invoked immediately after the ‘new’ keyword, which is ‘AnyClass()’, represents the constructor of the class. It plays a crucial role in setting up the object by initializing member data and methods and associating them with the ‘AnyClassObject’ instance.

18. How many types of constructors are available in OOPs?
Types of constructors:
•Default Constructor doesn’t take any argument. It has no parameters.
•Copy Constructor is responsible for duplicating an object, along with its values, into another object, provided that both objects belong to the same class.
•Parameterized Constructor take some arguments.
•Explicit Constructor is marked as explicit in its declaration. Prevents implicit type conversions during object initialization. Used to avoid unexpected type conversions that may lead to errors.
•Inline Constructor defined within the class declaration itself. Automatically inlined by the compiler for efficiency. Typically used for small, simple constructors.

19. What is a destructor?
Destructors are also specialized methods, that release the resources and memory held by an object. Destructors are automatically invoked when an object is undergoing destruction.

20. What is an Abstract class and Abstract methods?
Any class having abstract methods are known as Abstract class.
Abstract methods are the methods that are declared but not defined and at the time of use in some subclass these methods have to be exclusively defined in the subclass.

21. What are access specifiers or modifiers?
Access specifiers, as their name implies, are special keywords used to regulate or define the accessibility of entities such as classes, methods, and more. Common access specifiers or access modifiers include terms like ‘private,’ ‘public,’ and others. These access specifiers also play a crucial role in realizing Encapsulation, a fundamental feature of Object-Oriented Programming.

22. What is meant by Garbage Collection in OOPs?
Garbage collection is the mechanism used for managing memory in a program. It involves automatically releasing unneeded memory by eliminating objects that are no longer in use. It’s important to note that not all programming languages with OOP support have garbage collection. For example, in languages like C++, developers are responsible for manual memory management using constructors and destructors or by employing smart pointers to manage memory automatically.

23. What is an exception and how do you handle them?
An exception is a message that disrupts the normal flow of a program when an issue arises. Exceptions serve to report errors and transfer control to an exception handler for resolution. When an exception is raised, the program’s state is saved.
Exceptions are basically conditions that an application might try to catch.

24. What is a try/ catch block in OOPs?
The terms ‘try’ and ‘catch’ pertain to the approach used to manage exceptions that arise due to coding or data errors during program execution. The segment of code in which exceptions are likely to occur is known as a ‘try block.’ Any exceptions emanating from try blocks are captured and managed within a ‘catch block.

25. What is Cohesion in OOPs?
The modules having well-defined and specific functionality which improves the maintainability and reusability of code are called cohesion.

admin
http://www.learnwithgeeks.com

Leave a Reply