Question:- What are the advantages and disadvantages of OOP?
Answer:- Advantages of OOP It follows a bottom-up approach. It models the real word well. It allows us the reusability of code. Avoids unnecessary data exposure to the user by using the abstraction. OOP forces the designers to have a long and extensive design phase that results in better design and fewer flaws. Decompose a complex problem into smaller chunks. Programmer are able to reach their goals faster. Minimizes the complexity. Easy redesign and extension of code that does not affect the other functionality. Disadvantages of OOP Proper planning is required. Program design is tricky. Programmer should be well skilled. Classes tend to be overly generalized.
Question:- What are the limitations of OOPs?
Answer:- • Requires intensive testing processes. • Solving problems takes more time as compared to Procedure Oriented Programming. • The size of the programs created using this approach may become larger than the programs written using the procedure-oriented programming approach. • Software developed using this approach requires a substantial amount of pre-work and planning. • OOP code is difficult to understand if you do not have the corresponding class documentation. • In certain scenarios, these programs can consume a large amount of memory. • Not suitable for small problems. • Takes more time to solve problems.
Question:- What do you understand by pure object-oriented language? Why Java is not a pure object-oriented programming language?
Answer:- The programming language is called pure object-oriented language that treats everything inside the program as an object. The primitive types are not supported by the pure OOPs language. There are some other features that must satisfy by a pure object-oriented language: • Encapsulation • Inheritance • Polymorphism • Abstraction • All predefined types are objects • All user-defined types are objects • All operations performed on objects must be only through methods exposed to the objects. Java is not a pure object-oriented programming language because pre-defined data types in Java are not treated as objects. Hence, it is not an object-oriented language.
Question:- What do you understand by class and object? Also, give example.
Answer:- • Class: A class is a blueprint or template of an object. It is a user-defined data type. Inside a class, we define variables, constants, member functions, and other functionality. It does not consume memory at run time. Note that classes are not considered as a data structure. It is a logical entity. It is the best example of data binding. • Object: An object is a real-world entity that has attributes, behavior, and properties. It is referred to as an instance of the class. It contains member functions, variables that we have defined in the class. It occupies space in the memory. Different objects have different states or attributes, and behaviors.
Question:- What is the concept of access specifiers when should we use these?
Answer:- In OOPs language, access specifiers are reserved keyword that is used to set the accessibility of the classes, methods and other members of the class. It is also known as access modifiers. It includes public, private, and protected. There is some other access specifier that is language-specific. Such as Java has another access specifier default. These access specifiers play a vital role in achieving one of the major functions of OOP, i.e. encapsulation. The following table depicts the accessibility.
Question:- What are the manipulators in OOP and how it works?
Answer:- 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.
Question:- What are the rules for creating a constructor?
Answer:- • It cannot have a return type. • It must have the same name as the Class name. • It cannot be marked as static. • It cannot be marked as abstract. • It cannot be overridden. • It cannot be final.
Question:- What are the characteristics of an abstract class?
Answer:- 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 The purpose of an abstract class is to provide a common definition of the base class that multiple derived classes can share.
Question:- Is it possible for a class to inherit the constructor of its base class?
Answer:- No, a class cannot inherit the constructor of its base class.
Question:- Identify which OOPs concept should be used in the following scenario?
Answer:- A group of 5 friends, one boy never gives any contribution when the group goes for the outing. Suddenly a beautiful girl joins the same group. The boy who never contributes is now spending a lot of money for the group. Runtime Polymorphism
Question:- What is composition?
Answer:- Composition is one of the vital concepts in OOP. It describes a class that references one or more objects of other classes in instance variables. It allows us to model a has-a association between objects. We can find such relationships in the real world. For example, a car has an engine. the following figure depicts the same
Question:- What are the differences between copy constructor and assignment operator?
Answer:- The copy constructor and the assignment operator (=) both are used to initialize one object using another object. The main difference between the two is that the copy constructor allocates separate memory to both objects i.e. existing object and newly created object while the assignment operator does not allocate new memory for the newly created object. It uses the reference variable that points to the previous memory block (where an old object is located).
Question:- What is the difference between Composition and Inheritance?
Answer:- Inheritance means an object inheriting reusable properties of the base class. Compositions mean that an object holds other objects. In Inheritance, there is only one object in memory (derived object) whereas, in Composition, the parent object holds references of all composed objects. From a design perspective, inheritance is "is a" relationship among objects whereas Composition is "has a" relationship among objects.
Question:- What is constructor chaining?
Answer:- In OOPs, constructor chaining is a sequence of invoking constructors (of the same class) upon initializing an object. It is used when we want to invoke a number of constructors, one after another by using only an instance. In other words, if a class has more than one constructor (overloaded) and one of them tries to invoke another constructor, this process is known as constructor chaining. In C++, it is known as constructor delegation and it is present from C++ 11.
