(a) Define encapsulation.
Answer
The wrapping of data and methods that operate on that data into a single unit is called Encapsulation.
(b) Explain the purpose of using a 'new' keyword in a Java program.
Answer
The new keyword instantiates an array or a class by dynamically allocating memory for it at runtime and returning a reference to that memory.
For example:
Employee emp = new Employee();
Here we are creating an object of class Employee using the new keyword.
(c) What are literals?
Answer
Any constant value which can be assigned to the variable is called as literal. There are different types of literals like integer literals, floating point literals, character literals, String literals, boolean literals and null literals.
(d) Mention the types of access specifiers.
Answer
There are four types of access specifiers:
(e) What is constructor overloading?
Answer
Constructor overloading is a technique in Java through which a class can have more than one constructor with different parameter lists. The different constructors of the class are differentiated by the compiler using the number of parameters in the list and their types.
For example, a class Employee can have 3 constructors as shown below:
Employee(long empId)
Employee(String name, double salary)
Employee(long empId, String name)
Due to constructor overloading, all the 3 constructors are valid for Employee class.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.