Top 150+ Java Interview Questions and Answers

    58 Votes

25. What is encapsulation?

Encapsulation helps to implement one of the four fundamental Object Oriented Programming concepts, i.e. data hiding. It is the ability of an object to bind together the data (properties) and functions that manipulate the data, safe from outside manipulations. As per Grady Booch, encapsulation is defined as: “The process of hiding all of the details of an object that do not contribute to it's essential characteristics.
26. What is abstraction?

Data Abstraction is the process of hiding unnecessary details, exposing relevant information of an object suited for the system under consideration. Best example is an interface.

27. What is the difference between encapsulation and abstraction?
Encapsulation hides the irrelevant details of an object and Abstraction makes only the relevant details of an object visible.
28. What is inheritance?

Inheritance is the capability of a class to use the properties and methods of another class while adding it's own functionality. It enables you to add new features and functionality to an existing class without modifying the existing class.

29. What is superclass and subclass?

  • A superclass or parent class is the one from which another class inherit's attributes and behavior.
  • A subclass or child class is a class that inherit's attributes and behavior from a superclass.

30. What are the types of inheritance?

  • Single inheritance 
  • Multiple inheritance

31. What is single inheritance?

Subclass is derived from only one superclass.

Single inheritance

32. What is multiple inheritance?

A subclass is derived from more than one super class

Multiple inheritance

33. What is polymorphism?

Polymorphism is defined as the ability of an object to take multiple forms depending on their type or class. The best example of Polymorphism is, invoking derived class methods through a base class reference at run-time.

34. Describe method overloading with example?

Java allows to define several methods with same name within a class, but with different method signature. Methods are identified with the parameters set based on:

  • the number of parameters
  • types of parameters and
  • order of parameters.

Example of Method overloading is as given below.

int sum(int a,int b) { return a+b;}
int sum(int a,int b,int c) { return a+b+c;}
float sum(float a, float b, float c) { return a+b+c;}

35. How to identify starting method of a program ?

Method starting with following code
public static void main (String args[])
{
}

Java Interview Questions on Classes & Packages

36. How do we access data members of a class in java?

Dot Operator(.) is used to access the data members of a class outside the class by specifying the data member name or the method name.

Page 3 of 14

Popular Videos

communication

How to speak so that people want to listen.

Got a tip or Question?
Let us know

Related Articles

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