36 Commonly Asked Interview Questions — OOPS Concept

Balaji S B
Proggy Blast
Published in
5 min readDec 6, 2020

Hello everyone. This article is about who is preparing their interview. Here I have mentioned some of the common interview questions on OOPS concept. These are the concepts where most of you guys are aware about it. But I am happy to share my knowledge here with you. Please find the questions and answers below.

  1. What are the OOPS concpets generally used?

There are 4 oops concepts we used in our programmatic.

  • Abstraction
  • Encapsulation
  • Inheritance
  • Poymorphism

2. What is Abstraction?

Abstraction is the concept where we can hide all the logics from the user. The end user can able to access the method and get the response, but the user is not aware about what’s happening behind the screens.

3. How we can achieve abstraction?

We can achieve abstraction in 2 ways.

  • Abstract Class
  • Interface

4. What is Abstract Class?

A class denoted with abstract keyword is considered as abstract class. An abstract class must have atleast one abstract method (only function declaration with abstract keyword). But an abstract class can have non abstract method also (like normal function with body).

5. Can we create instance for abstract class?

No, we can’t create the instance for abstract class. We can extend abstract class to other class.

6. What is Interface?

Interface is a kind of abstraction where it have only function declaration. It don’t have function body. But from Java 8 we can create function with body with the help of static and final.

7. Which abstraction is good?

In general abstract classes are good for whenever you can reuse the same functionality for different classes. Here we can declare abstract methods too. So for the reusable concept abstract classes are good. But here the restriction is we can’t extend more than one classes in oops.

Where on the other hand we can implement multiple interfaces and implement own logic on each and every implemented classes.

8. What is Encapsulation ?

Encapsulation is a kind of class where we can restrict the user to modify the value directly from outside. We can access all the variables and results with the help of public methods.

9. When we say a class in encapuslated?

A class where all the declared fields are in private and all the updating values are in private that class is considered as encapsulated class.

10. What is Inheritance?

Inheritance is defined as the parent child relationship. Where a class can extend one class and can be extended by multiple classes.

11. How can we achieve inheritance?

If we want to use the methods or variables from one class to other class, we can achieve it with the help of inheritance. With the help of the extend keyword we can inherit another class. With the help of implements keyword we can inherit another interface.

12. What are the types of inheritance?

There are 4 types of inhertance.

  • Single Inheritance
  • Multiple Inheritance
  • Mulitlevel Inheritance
  • Hybrid Inheritance

13. Define single inheritance.

If there is one child class can extend or implement only one class or interface is known as single inheritance.

Eg. Class A -> Class B

14. Define Multiple inheritance.

An class can extend more than one class is multiple inheritance.

Eg. Class A -> Class B, Class C

15. Define Multilevel inheritance.

An class can be extended by different classes is known as multi level inheritance.

Eg. Class B -> Class A, Class C -> Class A

16. Define hybrid inheritance.

The combination of multiple and multilevel inheritance is known as hybrid inheritance.

Eg. Class C -> Class A, Class B, Class D -> Class A, Class E -> Class A

17. Is java supports multiple inheritance?

No, java doesn’t support multiple inheritance. Because it leads to occur diamond problem.

18. What is diamond problem?

When we are extending different classes into one class and try to call one method which is available in both class means, the compiler is get confused to consume which method implementation. This problem is known as diamond problem.

19. What is Polymorphism?

Polymorphism is defined as a class can be in many form. We can create instance for child class and assign it into parent class.

20. What are the types of polymorphism?

There are two types of polymorphism there.

  • Compile Time polymorphism
  • Run time polymorphism

21. Define Compile Time polymorphism.

Method or function overloading is generally known as compile time polymorphism.

22. What is method or function overloading?

Method or function overloading is where the function name is same and it has different return type with different parameters. We can achieve compile time polymorphism or method overloading with in the same class.

23. Define Runtime polymorphism.

Method or function overriding is generally known as runtime polymorphism.

24. What is method overriding?

Method overriding is defined as the same method name with same parameter and with same return type. We can achieve overriding through inheritance. We can override the method of the parent class to the child class with the help of override annotation.

25. What is class?

A class is the blueprint where it has all the variables and functions as business logic implementations.

26. What is Object?

An object is the instance where we can able to consume the class variable and methods with the help of instance.

27. How can we create the object?

With the help of the new keyword and class constructor method we can achieve the object or instance creation.

28. Define constructor.

Constructor is the kind of method where the class name and function name both are same without return type.

Eg.

Class A {

A(){

}

}

29. What are the types of constructor?

There are two types of constructor.

  • Default constructor (without any parameter)
  • Parameterized constructor ( with more than one parameter)

30. Do we need to create the constructor for the class?

No, by default every class has the default constructor which is used to create the object of the class.

31. What are the visibility modifiers?

Visibility modifiers are the visibility of the variable and function towards and outside of the class.

32. What are the different types of visible modifiers?

There are 4 types of visible modifers.

  • Private
  • Public
  • Protected
  • Default

33. Define Primary visible modifiers.

Variables or functions declared as private we can access the variable or function with in the same class only.

34. Define Public visible modifiers.

Variables or functions declared as public where we can access the variable or function from any class. We can create the instance of the class and with the help of the instance we can access the public methods and variables.

35. Define Protected visible modifiers.

Variables or functions declared as protected where we can access the variable or function from the inherited class. Whoever is extending the class, they only can able to access the protected variables or functions. This is generally used in inheritance.

36. Define Default visible modifiers.

If we doesn’t declare the visibility of the variable or function then it consider as the default visible modifier. The scope of the variable is within the same package classes can access the variable or methods.

Conclusion :

This article is focusing on whoever is preparing their interview or whoever is want to brush up their oops concepts. Please do clap (👏) if you like this post. Thanks and Cheers.

#Interview #OOPS #Balaji Balaji S B Proggy Blast

--

--

Balaji S B
Proggy Blast

Technical Lead @ Happeist Minds Technologies Pvt Ltd