Java oOP Interview Questions For Fresher 2022

1. What is Java?

Java is a computer programming language that is concurrent, class-based and object-oriented. The advantages of object oriented software development are shown below:

• Modular development of code, which leads to easy maintenance and modification.
• Reusability of code.
• Improved reliability and flexibility of code.
• Increased understanding of code.

Object-oriented programming contains many significant features, such as encapsulation, inheritance, polymorphism and abstraction. We analyze each feature separately in the following sections.

2. What is Encapsulation ?

Encapsulation is the process of wrapping or binding of the data(variables) and code acting on the data (methods) in a single unit. A simple Example of the is medicine capsule which is mixed of several medicines.

Important points about Encapsulation

  • Encapsulation is also known as the data-hiding.Because in this data is hidden from other classes.
  • Hidden data can only be accessed by member function of own class not by the other class.
  • Interfaces class is the example of a fully encapsulated class.
  • To achieve the proper security for data not being modified we use encapsulation

Encapsulation in java can be achieved by:

1. By making all the member of the class private

2. Use setter and getter methods to set and get the data.

3. What is Polymorphism ?

Polymorphism is defined as the process of performing the same action in different ways.It is the combination of two words poly and morphism.where “poly” means

. That means a single instance can have more then one form. In java polymorphism is achieved through methods.

Real life Example of polymorphism: Water can have different forms at different place.Like solid,liquid,and gas.So the water possessing different behaviour in different situations. This is called polymorphism.

⇒ Types of Polymorphism :-

We have two types of polymorphism in java.

  1. Compile time Polymorphism
  2. Run-time Polymorphism

Polymorphism is the ability of programming languages to present the same interface for differing underlying data types. A polymorphic type is a type whose operations can also be applied to values of some other type.

4. What is Inheritance ?

Inheritance provides an object with the ability to acquire the fields and methods of another class, called base class. Inheritance
provides re-usability of code and can be used to add additional features to an existing class, without modifying it.

5 .What is Abstraction ?

Abstraction is the process of hiding the implementation or details and showing the main services or the interfaces to the user. Basically Abstraction deals with exposing the interfaces to the user and hiding their implementations.

Real life Example of Abstraction: As in the car case,relevant parts like stearin,gear,horn,accelerator,breaks etc are shown to driver because they are necessary for driving. But driver need not understand the internal functioning of engine, gear, break etc. Showing the interface to the user and hiding the implementation is called as the Abstraction.

In java, abstraction is achieved by two ways:

  1. Abstract class
  2. Interface

By using interfaces we can achieve 100% Abstraction and by using Abstract class it is in between 0 to 100%.

Important terms about Abstraction

Abstract class : An abstract class is a class that is declared with abstract keyword.

  1. An abstract class not compulsion that it can have only abstract method some of them can be concrete.
  2. Any class that having abstract method then that class must be declared with abstract keyword.
  3. Abstracted class can’t be directly instantiated using new keyword. That means we cant create the object of Abstract class.
  4. If any regular class extends an abstract class, then class must have to implement all the abstract methods of the abstract parent class

Abstract method: An abstract method is a method which is declared without an implementation.

1. A method defined abstract need to be redefine in the subclass,thus to making overriding compulsory

2. It is necessary that an abstract must have abstract class but its inverse is not right.

6. What is Encapsulation ?

Encapsulation is the process of wrapping or binding of the data(variables) and code acting on the data (methods) in a single unit. A simple Example of the is medicine capsule which is mixed of several medicines.

Important points about Encapsulation

  • Encapsulation is also known as the data-hiding.Because in this data is hidden from other classes.
  • Hidden data can only be accessed by member function of own class not by the other class.
  • Interfaces class is the example of a fully encapsulated class.
  • To achieve the proper security for data not being modified we use encapsulation

Encapsulation in java can be achieved by:

1. By making all the member of the class private

2. Use setter and getter methods to set and get the data.

7. What is The Differences between Abstraction and Encapsulation

Abstraction and encapsulation are complementary concepts. On the one hand, abstraction focuses on the behavior of an object. On the other hand, encapsulation focuses on the implementation of an object’s behavior. Encapsulation is usually achieved by hiding information about the internal state of an object and thus, can be seen as a strategy used in order to provide abstraction

Leave a Comment