25. What is encapsulation?
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.
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.

32. What is multiple inheritance?
A subclass is derived from more than one super class

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.