Java OOPS Interview Questions and Answers

    52 Votes

11. What is Abstraction?

Abstraction is separating the functions and properties that can be logically separated in to a separate entity. Abstraction in Object Oriented Programming helps to hide the irrelevant details of an object. 
12. Define Encapsulation
Process of hiding all internal details of an object from out side the world.Encapsulation is a language mechanism to restrict the access of the Objects components to other Objects or Classes. 

 

13. What is Inheritance ?
In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects. A class can inherit attributes and behaviour from pre-existing class called base classes, super classes, or parent classes. The resulting class is known as derived classes, subclasses, or child classes.
14. What is Polymorphism ?

The occurrence of something in different forms. In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes.

15. What is Overloading ?

Overloading is one type of polymorphism. Overloading allows an object to have different meanings depending on its context. The term is used most often in reference to operators that can behave differently depending on the data type, or class, of the operands.

 

16. How do you implement inheritance in Java?

In Java, Inheritance is Implemented by "EXTEND" keyword.
public class employee extends person {
 
}

17. How can we implement polymorphism in Java?

Java has excellent support of polymorphism in terms of
  • Method Polymorphism through overloading and overriding
  • Object polymorphism through inheritance / Interface 

18. Define overriding in Java

when you extend a class and write a method in the derived class which is exactly similar to the one present in the base class, it is termed as overriding.
public class Vehicle {
    public String getEngineType(){
        //some code here
    }
}
public class Train extends Vehicle {
public String getEngineType(){
        //some new code here
    }
} 

As you can see, in the class Vehicle , we have overridden the method present in the BaseClass (Vehicle ) with a completely new piece of code.

19. Define overloading in Java

when you have more than one method with the same name but different arguments, the methods are said to be overloaded.
Public void saveUserInfo(int userId){
 
}
public void saveUserInfo(String userName,String Location){
 
}
20. Differentiate method overriding and overloading in Java ?

Method overloading deals with the notion of having two or more methods(functions) in the same class with the same name but different arguments. While Method overriding means having two methods with the same arguments, but different implementation. One of them would exist in the Parent class (Base Class) while another will be in the derived class(Child Class).@Override annotation is required for this.

Page 2 of 3

Popular Videos

communication

How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

Java Interview Questions
Top Advanced Java Interview Questions and Answers
Java Collections Interview Questions and Answers
Java Thread Interview Questions and Answers