1.What is Object-oriented Programming?
Object-oriented programming is a programming model or approach where the programs you create are organized around objects rather than logic and functions. The states and behaviors of an object are represented as member variables and methods. This approach is ideal for the programs that are large and complex and need to be actively updated or maintained. Here below is an example of OOP where this little piece is focused on Person. There can be other entities like payment method, Account, etc. Programs are organized into entities.
2. What are the advantages of OOPs?
Simplicity: Domain models or entities are modeled after real-world objects. It is easier to understand and to relate to. The program structure is also easier to comprehend.
Modularity: Each object is decoupled from other objects of the system.
Modifiability: It is easy to make minor changes in the data or the functionalities in an OO program. Changes inside a class do not affect any other part of a program since the only public interface that the external world has to a class is through the use of methods.
Extensibility: Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones.
Maintainability: Objects can be maintained separately, making locating and fixing problems easier.
Reusability: Objects can be reused in different programs.
3. What is the difference between procedural programming and OOPs?
4. What are the core concepts of OOPs?
5. What is the difference between Abstraction and Encapsulation?
6. What is the diamond problem in inheritance?
In the case of multiple inheritances, suppose class A has two subclasses B and C, and class D has two superclasses B and C. If a method present in A is overridden by both B and C but not by D then from which class D will inherit that method B or C? This problem is known as the diamond problem.
7. Why Java does not support multiple inheritances?
Java was designed to be a simple language and multiple inheritances introduce complexities like the diamond problem. Inheriting states or behaviors from two different types of classes is a case which in reality very rare and it can be achieved easily through an object association.
8. What is Static Binding and Dynamic Binding?
Static or early binding is resolved at compile time. Method overloading is an example of static binding. Static binding is faster than dynamic binding.
Dynamic or late or virtual binding is resolved at run time. Method overriding is an example of dynamic binding. This decision making during runtime makes Dynamic binding slower than static binding.
9. What is the meaning of the “IS-A” and “HAS-A” relationship?
“IS-A” relationship implies inheritance. A subclass object is said to have an “IS-A” relationship with the superclass or interface. If class A extends B then A “IS-A” B. It is transitive, that is, if class A extends B and class B extends C then A “IS-A” C. The “instance of” operator in java determines the “IS-A” relationship.
When a class A has a member reference variable of type B then A “HAS-A” B. It is also known as Aggregation.
10. What is an Association?
Association is a relationship between two objects with multiplicity.
11. What is Aggregation?
Aggregation is also known as “HAS-A” relationship. When class Car has a member reference variable of type Wheel then the relationship between the classes Car and Wheel is known as Aggregation. Aggregation can be understood as “whole to its parts” relationship.
Car is the whole and wheel is part. The wheel can exist without the Car. Aggregation is a weak association.
12. What is Composition?
Composition is a special form of Aggregation where the part cannot exist without the whole. Composition is a strong Association. Composition relationship is represented like aggregation with one difference that the diamond shape is filled.
13. What is Dependency?
When one class depends on another because it uses that class at some point in time then this relationship is known as Dependency. One class depends on another if the independent class is a parameter variable or local variable of a method of the dependent class. A Dependency is drawn as a dotted line from the dependent class to the independent class with an open arrowhead pointing to the independent class.
14. What is the difference between Association and Dependency?
The main difference between Association and Dependency is in case of Association one class has an attribute or member variable of the other class type but in case of Dependency a method takes an argument of the other class type or a method has a local variable of the other class type.