The Top 10 Interview Question in Java
1. What is Java?
Java is a high-level, object-oriented, robust, secure programming language, platform-independent, high-performance, Multithreaded, and portable programming language. It was developed by James Goslingin June 1991. It can also be known as the platform as it provides its own JRE and API.
2. What is the platform?
A platform is the hardware or software environment in which a piece of software is executed. There are two types of platforms, software-based and hardware-based. Java provides the software-based platform.
3. What are the advantages of Packages in Java?
There are various advantages of defining packages in Java.
1. Packages avoid the name clashes.
2. The Package provides easier access control.
3. We can also have the hidden classes that are not visible outside and used by the package.
4. It is easier to locate the related classes.
4. What is an object?
The Object is the real-time entity having some state and behavior. In Java, Object is an instance of the class having the instance variables as the state of the object and the methods as the behavior of the object. The object of a class can be created by using the new keyword.
5. What is the constructor?
The constructor can be defined as the special type of method that is used to initialize the state of an object. It is invoked when the class is instantiated, and the memory is allocated for the object. Every time, an object is created using the new keyword, the default constructor of the class is called. The name of the constructor must be similar to the class name. The constructor must not have an explicit return type.
6. How many types of constructors are used in Java?
Based on the parameters passed in the constructors, there are two types of constructors in Java.
Default Constructor: default constructor is the one which does not accept any value. The default constructor is mainly used to initialize the instance variable with the default values. It can also be used for performing some useful task on object creation. A default constructor is invoked implicitly by the compiler if there is no constructor defined in the class.
Parameterized Constructor: The parameterized constructor is the one which can initialize the instance variables with the given values. In other words, we can say that the constructors which can accept the arguments are called parameterized constructors.
7. What is Inheritance?
Inheritance is a mechanism by which one object acquires all the properties and behavior of another object of another class.
8. What are the Types of Inheritance?
There are five types of inheritance in Java.
- Single-level inheritance
- Multi-level inheritance
- Multiple Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
9. What is aggregation?
Aggregation can be defined as the relationship between two classes where the aggregate class contains a reference to the class it owns. Aggregation is best described as a has-a relationship
10. What is composition?
Holding the reference of a class within some other class is known as composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition.
For More Interview Questions About Java: https://bit.ly/3VsJjhf
Comments
Post a Comment