Header Ads

test

interview question of oops concept



Oops based question and answer for interview:
---------------------------------

1.What is oops?
Ans.OBJECT ORIENTED PROGRAMMING (OOP) is a programming concept that works on the
principles of abstraction, encapsulation, inheritance, and polymorphism.

2.Why oops?
Ans.Because it make visualization easier because it is closest to real world scenarios.
You can reuse the code, this saves time, and shrinks your project.
OOP provides a clear modular structure for programs.




3.What are class and objects?

Ans.Class is a logical entity it contains logics whereas object is physical entity it is representing memory.
Class is blue print it decides object creation without class we are unable to create object.
4.Why we use class?
Ans.  For code reusibility
   for increase security of code

5.Why we create object?

Ans.for implementation of class in real world




6.Why we use Encapsulation?

Ans.It’s because encapsulation has a number of advantages that increase the reusability, flexibility and maintainability of the code.

Flexibility: It’s more flexible and easy to change the encapsulated code with new requirements. For example, if the requirement for setting the age of a
person changes, we can easily update the logic in the setter method setAge(). 

Reusability: Encapsulated code can be reused throughout the application or across multiple applications. For example, the Person class can be reused whenever such type of object is required. 
Maintainability: Application ode is encapsulated in separate units (classes, interfaces, methods, setters, getters, etc) so it’s easy to change or update a part of the application  without affecting other parts, which reduces the time of maintenance

7.Why we use inheritance ?

ü Inheritance is for reusing code. When you want to extend features of a class, you can write a subclass to inherit all data and behaviors of that superclass. This saves time on writing code.
ü Another reason for implementing inheritance is for the purpose of extensibility. It’s easier to extend a class and add new features than writing a new class from scratch.

8.Define the term constructor?
               
ü Constructors are used to write block of java code that code will be executed during object creation.
ü Constructors are used to initialize instance variables during object creation.




9.Why we use super keyword?

Ans.
super” keyword is used to represent super class object.
1. Super class variables.
2. Super class methods.
3. Super class constructors.
4. Super class instance blocks.
5. Super class static blocks.


10.What are the main building blocks of oops?

Ans.
1. Inheritance
2. Polymorphism
3. Abstraction
4. Encapsulation….etc


11.How to achieve inheritance concept and inheritance is also known as.

Ans. Inheritance concept achieve by using extend keyword. it is also known as Is-A relationship.

12. One class able to extends how many classes at a time?

Ans. Only one

13.What is the purpose of extends keyword?
Ans.The purpose of Extends keyword is providing relationship between two classes.






14.What is inheritance?
Ans.
1.The process of acquiring properties (variables) & methods (behaviors) from one class to another class is called inheritance.
2. We are achieving inheritance concept by using extends keyword.
3.Inheritance is also known as is-a relationship.


15.What is Association?

Ans.Association is relation between  two separate classes which establishes through their Objects.
Composition and Aggregation are the two forms of association.





16.What is Aggregation?
Ans.It is Weak form of Association. It also known as Has-A relationship.
When there is a composition between two entities, the composed object can exist without the other entity.
Example.
Relationship between teacher and department

17.What is composition?
Ans.
Composition is a restricted form of Aggregation in which two entities are highly dependent on each other.
It represents part-of relationship.
In composition, both the entities are dependent on each other.
When there is a composition between two entities, the composed object cannot exist without the other entity.
Example. relatioship between student and marks

 18.What is polymorphism?
Ans.
ü The ability to appear in more forms is called polymorphism.
ü One thing can exhibits more than one form is called polymorphism.
ü One functionality with different actions is called polymorphisum.
ü One person with different behaviours is called polymorphism
ü Polymorphism is a Greek word poly means many and morphism means forms.
There are two types of polymorphism in java,
1) Compile time polymorphism / static binding / early binding
Example :- method overloading.
2) Runtime polymorphism /dynamic binding /late binding.
Example :- method overriding.


 19.What do you mean by Encapsultation?

Ans.The process of binding the data and code as a single unit is called encapsulation.
             Or
 The process of hiding the implementation details to user is called encapsulation
 we are achieving this concept by declaring variables as a private modifier  because it is possible to access private members with in the class only.
Note: The data of the private field can be
accessed only by using public setter & getter method

20.What is Abstraction?

Ans.The process highlighting the set of services and hiding the internal  implementation is called abstraction.
Bank ATM Screens Hiding the internal implementation and
highlighting set of services like , money transfer, mobile registration,…etc).
We are achieving abstraction concept by using Abstract classes & Interfaces.

21.How can you acheive 100% abstraction?

Ans.By using interface

22.How can you prevent object creation?
Ans. By using Abstract class

23.How we preventing inheritance?

Ans. For preventing inheritance we have to prevent subclass or child class creation . we have to declare our class as final with help of final modifier that restrict to create subclass.

24.We know very well java doesn't support  multilple inheritance so how can we achieve?

Ans. By using interface

25.Does method overloading depends on return type of method?

Ans. NO . it's depend only signature of method. Method signature  means method_name and argument.

26.Can we hold Parent class object into child class reference?

Ans. No











No comments