Java Interview Questions and Answers For Graduates Part-5
41.What is Polymorphism?
Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
42.What is Abstraction?
It refers to the ability to make a class abstract in OOP. It helps to reduce the complexity and also improves the maintainability of the system.
43.What is Abstract class?
These classes cannot be instantiated and are either partially implemented or not at all implemented. This class contains one or more abstract methods which are simply method declarations without a body.
44.When Abstract methods are used?
If you want a class to contain a particular method but you want the actual implementation of that method to be determined by child classes, you can declare the method in the parent class as abstract.
45.What is Encapsulation?
It is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. Therefore encapsulation is also referred to as data hiding.
46.What is the primary benefit of Encapsulation?
The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this Encapsulation gives maintainability, flexibility and extensibility to our code.
47.What is an Interface?
An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
48.Give some features of Interface?
It includes −
Interface cannot be instantiated
An interface does not contain any constructors.
All of the methods in an interface are abstract.
49.Define Packages in Java?
A Package can be defined as a grouping of related types(classes, interfaces, enumerations and annotations ) providing access protection and name space management.
50.Why Packages are used?
Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations, etc., easier.