Important Interview Questions on OOPs in Java

In this article, I am going to share you the Important OOPS Interview Questions and Answers. This post on OOPs Interview Questions is prepared to help you to understand the basic concepts of Java’s OOPs for interview purposes. OOPs is one of the favorite topic to be asked by the interviewer in the interview to fresher as well as experienced candidates. As per my experience, OOPs topic is asked in every single interview. so never thinks to go for the interview by skipping this topic.

Q1. What is OOPs in java?
Ans:
Object Oriented Programming (OOP) is a way of programming, where the complete software work as a collection of objects interacting with each other. An object is a collection of data and methods that operate on its data.

Q2.What are the main features of OOP?
Ans: The main features of Object-oriented programming are as follows:

  • Encapsulation
  • Polymorphism
  • Inheritance
  • Abstraction

Q3. What do you understand by encapsulation?
Ans:
Mechanism of wrapping the data (variable and method in a single unit). A process of defining properties and operation for an entity, that is declaring or defining a member of a class with visibility labels and with proper access modifier is called encapsulation.
Declaring private member inside the class is called data hiding or encapsulation.

For Example:

public Class Hello
{
Private int a =10;
}

here, private is used with a variable ‘a’ so it cannot be accessible outside the Class Hello.

Q4. What is Inheritance in java?
Ans:
It is the process of defining a new class from the existing class functionality. In order to inherit the existing class. We need to use the ‘extends’ keyword. The main purpose of the inheritance is code reusability.
For example:

Class Hello { 
// super class 
} 
Class Hi extends Hello {
 // sub class 
}

Q5. What is Polymorphism in java?
Ans:
It is the process of behaving one form differently in different cases.
For example Consider, television remote has a red button, it is used to switch on the television and also to switch off the television. In this case, the red button functionally depends on the current state of the television. If it is switch on then it will be used to switch off and vice-versa.
Polymorphism can be accessed in different ways:

    • Runtime polymorphism ( method overriding)
    • Compile time polymorphism ( method overloading)

Q6. What is Abstraction?
Ans: Abstraction is the process of thinking before developing any program or any application. In other words, Abstraction is the process of defining properties and operation of an entity i.e, properties related to a variable, operation related to a method, entity related to the class. Consider, the mobile phone which has usually two buttons, one green button to receive the call another red button to cancel the call. We are not bothered about how the implementation of buttons is done or how they are working but we are just using it. In Java, abstraction can be achieved through the use of abstract classes and interfaces. 100% of abstraction can be achieved by using interfaces.

Q7. What are the Advantages of Abstraction?
Ans:
The advantage of the Abstraction are as follows:

  • Abstraction reduces the complexity of things or the code.
  • Reuse the code
  • Remove duplication of the code.
  • It helps to increase the security of an application as only important details are provided to the user.

Q8. What do you understand by Abstract classes and Abstract methods?
Ans:

    • An abstract keyword is used to make an abstract class.
    • An abstract method doesn’t have an implementation.
    • In the Abstract class, concrete methods may also present.
    • A method defined as an abstract must be defined in the subclass.
    • If any abstract method is defined in the class then that class must be declared as an abstract class.
    • An abstract class doesn’t have its object.

Q9. What is Object in Java?
Ans:
To access the members of the class in Java, an object is required to be created. An object is also known as an instance of the class. The multiple numbers of an object can be created for a class. In order to create an Object, we need to use the new keyword. An object is some memory location in which each and every type of information of a class can be stored in digital code format. An object is used to access the member of a class from outside the class.

Q10 What is Class in Java?
Ans:
Class in Java is a user-defined data type, group of similar kind of entities. It is only the logical concept, not the physical entity. In order to declare the class in java, we use ‘class’ keyword.
For example :
Acess Modifier Class [Class-name] { }
Public Class Hello
{
}

Q11. What are the type of members a class contain?
Ans:
A class can contain a different type of members

    • Variable
    • Blocks
    • Methods
    • Constructor
    • Inner Class
    • Enum

Q12. Is Java a pure object-oriented language? if not why?
Ans:
No, Java is not a pure object-oriented programming language. It means there are many things you can do without objects for example:- as we can call the static methods without the use of an object of the class., directly through the class name. And also, primitive variables are not objects in Java.

Conclusion: This article will help you with the Object-oriented programming top basic interview question and answer for the freshers and experienced candidates. Read the article carefully, I believe this article is going to help a lot to the fresher as well as experience candidate to tackle the question fired by the interviewer. Stay tuned!  for the more interview question. Happy Learning! All the best!

Recommended interview questions: